Changes

Jump to navigation Jump to search
8,546 bytes added ,  22:08, 6 April 2005
no edit summary
You find a lot of samples in [http://www.pragma-ade.com/general/manuals/enattab.pdf enattab.pdf]
Willi Egger wrote a [[My Way]] how he set a typesetter's lead type case: [http://wwwdl.pragma-adecontextgarden.com:8080net/context/Members/willi/My%20Waymyway/NaturalTables.pdf Use of natural tables]
<texcode>
\bTR \bTD[nc=3] 1/2/3 \eTD \bTD 4 \eTD \eTR
\bTR \bTD 1 \eTD \bTD 2 \eTD \bTD 3 \eTD \bTD 4 \eTD \eTR
\eTABLE
</context>
 
== Designing complex TABLEs ==
 
Everything is easy when a simple grid is enough. Unfortunately, this
is not the case most of the time, tables tend to have information
which should flow accross cell boundaries either vertically
or horizontally. One of the reasons to use TABLE instead of the
table environment is that TABLE provides an easy (relatively speaking,
at least) way to make merged cells to both directions.
 
There are probably as many ways to design TABLEs as there are
users, but a simple one to begin with is to start with a
grid:
 
<context>
\setupTABLE[r][each][height=1cm]
\setupTABLE[c][each][width=1cm]
\bTABLE
\bTR \bTD r1c1 \eTD \bTD r1c2 \eTD \bTD r1c3 \eTD \bTD r1c4 \eTD \bTD r1c5 \eTD \bTD r1c6 \eTD \eTR
\bTR \bTD r2c1 \eTD \bTD r2c2 \eTD \bTD r2c3 \eTD \bTD r2c4 \eTD \bTD r2c5 \eTD \bTD r2c6 \eTD \eTR
\bTR \bTD r3c1 \eTD \bTD r3c2 \eTD \bTD r3c3 \eTD \bTD r3c4 \eTD \bTD r3c5 \eTD \bTD r3c6 \eTD \eTR
\bTR \bTD r4c1 \eTD \bTD r4c2 \eTD \bTD r4c3 \eTD \bTD r4c4 \eTD \bTD r4c5 \eTD \bTD r4c6 \eTD \eTR
\bTR \bTD r5c1 \eTD \bTD r5c2 \eTD \bTD r5c3 \eTD \bTD r5c4 \eTD \bTD r5c5 \eTD \bTD r5c6 \eTD \eTR
\bTR \bTD r6c1 \eTD \bTD r6c2 \eTD \bTD r6c3 \eTD \bTD r6c4 \eTD \bTD r6c5 \eTD \bTD r6c6 \eTD \eTR
\eTABLE
</context>
 
The desired table layout is then drawn onto this grid, and the top left corner cell
of each cell in the final layout identified:
 
<context>
\setupTABLE[r][each][height=1cm]
\setupTABLE[c][each][width=1cm]
\setupTABLE[r][1][height=0cm,frame=off]
\bTABLE
\bTR \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \eTR
\bTR \bTD[nc=2,nr=2] r1c1 \eTD \bTD r1c3 \eTD \bTD[nr=2] r1c4 \eTD \bTD[nc=2,nr=2] r1c5 \eTD \eTR
\bTR \bTD[nr=2] r2c3 \eTD \eTR
\bTR \bTD[nc=2] r3c1 \eTD \bTD[nc=2] r3c4 \eTD \bTD r3c6 \eTD \eTR
\bTR \bTD r4c1 \eTD \bTD[nc=2] r4c2 \eTD \bTD[nr=2] r4c4 \eTD \bTD[nc=2] r4c5 \eTD \eTR
\bTR \bTD[nr=2,nc=2] r5c1 \eTD \bTD[nr=2] r5c3 \eTD \bTD[nr=2,nc=2] r5c5 \eTD \eTR
\bTR \bTD r6c4 \eTD \eTR
\eTABLE
</context>
 
The cells are listed from left to right and up to down. Each larger cell is then given
it size by using <tt>nc=...</tt> and <tt>nr=...</tt> parameters with <tt>\bTD</tt>. The
code producing the table above is:
 
<texcode>
\setupTABLE[r][each][height=1cm]
\setupTABLE[c][each][width=1cm]
\setupTABLE[r][1][height=0cm,frame=off]
\bTABLE
\bTR \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \eTR
\bTR \bTD[nc=2,nr=2] r1c1 \eTD \bTD r1c3 \eTD \bTD[nr=2] r1c4 \eTD \bTD[nr=2,nc=2] r1c5 \eTD \eTR
\bTR \bTD[nr=2] r2c3 \eTD \eTR
\bTR \bTD[nc=2] r3c1 \eTD \bTD[nc=2] r3c4 \eTD \bTD r3c6 \eTD \eTR
\bTR \bTD r4c1 \eTD \bTD[nc=2] r4c2 \eTD \bTD[nr=2] r4c4 \eTD \bTD[nc=2] r4c5 \eTD \eTR
\bTR \bTD[nr=2,nc=2] r5c1 \eTD \bTD[nr=2] r5c3 \eTD \bTD[nr=2,nc=2] r5c5 \eTD \eTR
\bTR \bTD r6c4 \eTD \eTR
\eTABLE
</texcode>
 
N.B. There is an ugly hack in the code. An empty first row with zero height and no borders
is added. If the row is omitted, then something odd happens to the number of
columns. The table should have all cells, so this may be a bug. (Or then I have
blundered something with this example, possibly.)
 
Everything rectangular can be done with TABLE, as long as it can be fit in the grid. The grid
does not have to be equidistant, and if its dimensions are omitted, the program
will fit the data in. L-shaped or other complex cell shapes are not possible.
Using them would be a bit odd, in any case, as alignment and text flow problems
would be quite interesting.
 
 
== Cell Addressing and Frames ==
 
The setup commands for TABLE do not seem to be very verbosedly commented.
There are, however, a few shorthands, which are useful to understand.
First of all, there are several ways to address cells. This is a brief
summary of some of them:
 
<texcode>
\setupTABLE[r][(list of rows)][...]
\setupTABLE[c][(list of columns)][...]
\setupTABLE[(list of columns)][(list of rows)][...]
</texcode>
 
A list contains one or more numbers separated by commas.
Word "last" is equivalent to the number of the last row or
column. The complete list can be replaced by the word "each"
to address all cells on the row/column.
 
Let us consider the following table:
 
<texcode>
\setupTABLE[c][each][align={middle,lohi},frame=off]
\setupTABLE[r][2,3,4,5,6][height=1.0cm]
\setupTABLE[r][2,4][topframe=on]
\setupTABLE[c][1,2,3][rightframe=on]
...
</texcode>
 
In plain language the rows are interpreted as follows:
 
* Align each cell in each column (i.e. all cells) horizontally in the middle
and vertically in the middle (lohi), and remove all frames (borders)
* The height of rows 2 -- 6 is 1.0 cm
* Draw a line on top of rows 2 and 4
* Draw a line to the right side of columns 1 -- 3
 
In this case the table is slightly complicated, there are some split cells,
as shown below:
 
<texcode>
\bTABLE
\bTR
\bTD \bf r1c1 \eTD
\bTD \bf r1c2 \eTD
\bTD \bf r1c3 \eTD
\bTD \bf r1c4 \eTD
\eTR
\bTR
\bTD r2c1 \eTD
\bTD r2c2 \eTD
\bTD[nr=2] r2c3 \eTD
\bTD r2c4 \eTD
\eTR
\bTR
\bTD r3c1 \eTD
\bTD r3c2 \eTD
\bTD r3c4 \eTD
\eTR
\bTR
\bTD r4c1 \eTD
\bTD r4c2 \eTD
\bTD[nr=3] r4c3 \eTD
\bTD[nr=3] r4c4 \eTD
\eTR
\bTR
\bTD r5c1 \eTD
\bTD r5c2 \eTD
\eTR
\bTR
\bTD r6c1 \eTD
\bTD r6c2 \eTD
\eTR
\eTABLE
</texcode>
 
The resulting table looks like:
 
<context>
\setupTABLE[c][each][align={middle,lohi},frame=off]
\setupTABLE[r][2,3,4,5,6][height=1.0cm]
\setupTABLE[r][2,4][topframe=on]
\setupTABLE[c][1,2,3][rightframe=on]
\bTABLE
\bTR
\bTD \bf r1c1 \eTD
\bTD \bf r1c2 \eTD
\bTD \bf r1c3 \eTD
\bTD \bf r1c4 \eTD
\eTR
\bTR
\bTD r2c1 \eTD
\bTD r2c2 \eTD
\bTD[nr=2] r2c3 \eTD
\bTD r2c4 \eTD
\eTR
\bTR
\bTD r3c1 \eTD
\bTD r3c2 \eTD
\bTD r3c4 \eTD
\eTR
\bTR
\bTD r4c1 \eTD
\bTD r4c2 \eTD
\bTD[nr=3] r4c3 \eTD
\bTD[nr=3] r4c4 \eTD
\eTR
\bTR
\bTD r5c1 \eTD
\bTD r5c2 \eTD
\eTR
\bTR
\bTD r6c1 \eTD
\bTD r6c2 \eTD
\eTR
\eTABLE
</context>
 
The cell numbering is well worth noting. It is very logical (upper
leftmost part of a combined cell), but sometimes the results are
surprising in the beginning.
 
The important point about cell numbering is that there is really
a difference between "bottom border of row 3" and "top border of
row 4". To illustrate this, let us change the frame setups:
 
<texcode>
\setupTABLE[r][2,4][topframe=on]
</texcode>
 
is changed to
 
<texcode>
\setupTABLE[r][1,3][bottomframe=on]
</texcode>
 
At first sight this is exactly the same thing. But...
 
<context>
\setupTABLE[c][each][align={middle,lohi},frame=off]
\setupTABLE[r][2,3,4,5,6][height=1.0cm]
\setupTABLE[r][1,3][bottomframe=on]
\setupTABLE[c][1,2,3][rightframe=on]
\bTABLE
\bTR
\bTD \bf r1c1 \eTD
\bTD \bf r1c2 \eTD
\bTD \bf r1c3 \eTD
\bTD \bf r1c4 \eTD
\eTR
\bTR
\bTD r2c1 \eTD
\bTD r2c2 \eTD
\bTD[nr=2] r2c3 \eTD
\bTD r2c4 \eTD
\eTR
\bTR
\bTD r3c1 \eTD
\bTD r3c2 \eTD
\bTD r3c4 \eTD
\eTR
\bTR
\bTD r4c1 \eTD
\bTD r4c2 \eTD
\bTD[nr=3] r4c3 \eTD
\bTD[nr=3] r4c4 \eTD
\eTR
\bTR
\bTD r5c1 \eTD
\bTD r5c2 \eTD
\eTR
\bTR
\bTD r6c1 \eTD
\bTD r6c2 \eTD
\eTR
\eTABLE
</context>
 
Where did the horizontal line in column 3 disappear? Nowhere. There is no
row 3 in column 3, so there cannot be a frame under it. This problem
can be overcome by using topframe and leftframe instead of bottom and
right, as the cells below and to the right of a border have to exist.
 
However, this solution leaves the problem of bottom and rightmost borders.
How to draw a line in the bottom of the table? Using
<tt>\setupTABLE[r][6][bottomframe=on]</tt> will leave the gap in columns 3 and 4,
and <tt>\setupTABLE[r][7][topframe=on]</tt> is not possible, as there is no
row 7. The clever idea of using "last" instead of the row number (6) will fail,
as "last" seems to behave exactly the same way as number 6.
 
One useful method is to switch on the borders cell by
cell by adding <tt>\setupTABLE[3,4][4][bottomframe=on]</tt>, i.e.
draw a border under cells r4c3 and r4c4.
 
<context>
\setupTABLE[c][each][align={middle,lohi},frame=off]
\setupTABLE[r][2,3,4,5,6][height=1.0cm]
\setupTABLE[r][2,4][topframe=on]
\setupTABLE[c][1,2,3][rightframe=on]
\setupTABLE[r][6][bottomframe=on]
\setupTABLE[3,4][4][bottomframe=on]
\bTABLE
\bTR
\bTD \bf r1c1 \eTD
\bTD \bf r1c2 \eTD
\bTD \bf r1c3 \eTD
\bTD \bf r1c4 \eTD
\eTR
\bTR
\bTD r2c1 \eTD
\bTD r2c2 \eTD
\bTD[nr=2] r2c3 \eTD
\bTD r2c4 \eTD
\eTR
\bTR
\bTD r3c1 \eTD
\bTD r3c2 \eTD
\bTD r3c4 \eTD
\eTR
\bTR
\bTD r4c1 \eTD
\bTD r4c2 \eTD
\bTD[nr=3] r4c3 \eTD
\bTD[nr=3] r4c4 \eTD
\eTR
\bTR
\bTD r5c1 \eTD
\bTD r5c2 \eTD
\eTR
\bTR
\bTD r6c1 \eTD
\bTD r6c2 \eTD
\eTR
\eTABLE
</context>
Anonymous user

Navigation menu