Changes

Jump to navigation Jump to search
6,910 bytes added ,  09:05, 22 August 2017
m
no edit summary
=Introduction=
This table mode The preferred way to typeset tables is to use what are called &ldquo;natural tables&rdquo; or (also known as &ldquo;automatic tables.&rdquo; I'd call it or &ldquo;HTML tables,&rdquo; because it's very similar to them). They're are especially suited for [[XML]] conversions. Beware: every element must use <tt>\b</tt> ... <tt>\e</tt>! You find a lot of samples in See the [[manual:enattab.pdf|enattab.pdf]] Willi Egger wrote a [[My Way]] how he set a typesetter's lead type case: [http://dl.contextgarden.net/myway/NaturalTablesmanual for many examples.pdf Use of natural tables]
To place a table use:
</texcode>
Here is a A more elaborate example:
<context source=yes>
This is our red-coloured table.
\setupcolors[state=start]
 
\setupTABLE[row][odd][background=color,backgroundcolor=red, width=.2\textwidth]
\bTABLE[split=yes] % allow splitting over page boundaries
</context>
Note that every element must use <tt>\b</tt> ... <tt>\e</tt>.
 
Willi Egger wrote a [[My Way]] how he set a typesetter's lead type case: [http://dl.contextgarden.net/myway/NaturalTables.pdf Use of natural tables]
= Multipage TABLEs =
Try to divide your table into...
* <{{cmd>|bTABLEhead</cmd> }} (table header)* <{{cmd>|bTABLEnext</cmd> }} (alternate table header on following pages)* <{{cmd>|bTABLEbody</cmd> }} (table body)* <{{cmd>|bTABLEfoot</cmd> }} (table footer)and <{{cmd>|setupTABLE</cmd>}}<tt>[split=yes]</tt> or <tt>[split=repeat]</tt>
see also [[source:tabl-ntb.mkiv|tabl-ntb.mkiv]]
In this case the <b>table head</b>
(all between <{{cmd>|bTABLEhead</cmd> }} and <{{cmd>|eTABLEhead</cmd>}})
is printed only once at the beginning of the table. But if you use <tt>[split=repeat]</tt>,
it is printed on top of every new page, that contains parts of
your multipage table. Please take account of the fact, that the
head cells are enclosed by <{{cmd>|bTH</cmd> }} and <{{cmd>|eTH</cmd> }} (and not \[be]TC).
If you want to use an alternative table header for all following pages,
you can do this by defining an additional header. Just add the second header
between <{{cmd>|bTABLEnext</cmd>}}...<{{cmd>|eTABLEnext</cmd>}},
right after your normal head definition.
Now every additional page of the multipage table starts with the
<b>next table head</b>.
The <b>table foot</b> is declared between <{{cmd>|bTABLEfoot</cmd> }} and<{{cmd>|eTABLEfoot</cmd>}}. It defines the concluding row of your natural table.
'''Beware:''' Split tables often begin not on the page (or in the column, if you use them) where they ''could'' start, but on/in the next one.
\stoptext
</texcode>
 
== Changing split location ==
 
Sometimes in multipage tables you have cells that have to stay together:
 
<texcode>
\bTABLE[split=yes]
\dorecurse{10}{\bTR \bTD xxx \eTD \eTR}
\bTR[after=\page] \bTD yyy \eTD \eTR
\dorecurse{10}{\bTR \bTD xxx \eTD \eTR}
\eTABLE
</texcode>
 
Note that the table is split after the yyy row.
= Tables in multiple columns =
\stoptext
</texcode>
 
== Row Offset/Gap ==
 
Rows, just like columns, can be drawn with a gap.
As above, this can be achieved using:
<texcode>
\bTABLE[spaceinbetween=2cm]
...
\eTABLE
</texcode>
 
A gap differs from an offset as can be seen when drawing
cells using a background and/or a frame.
 
Note that offsets can be uniform <tt>[offset=dimension]</tt>,
or asymmetric
<tt>[toffset=dimension,boffset=dimension,loffset=dimension,roffset=dimension]</tt>
 
=== Gaps for individual cells ===
 
One might want to produce gaps between specific rows and/or specific columns.
This can be achieved using a white frame, for example,
as shown in the following (incomplete) fragment:
 
<texcode>
\bTABLE[frame=off,columndistance=.5em]
...
\bTR[topframe=on,framecolor=white,rulethickness=.5em]
...
\eTR
...
\eTABLE
</texcode>
 
Note that the <tt>rulethickness</tt> was set for the particular row
and not for the entire table; otherwise, it would enter into the
calculation of the cell dimensions (and interplay with other parameters
such as <tt>columndistance</tt>).
 
More complicated situations, for example, mixing frames, colored cell backgrounds, special gaps, ..., can be achieved using MetaPost graphics as a <tt>background</tt>.
== Make a cell bold ==
<tr><td style="background-color:#DDDDDD" align="center">4</td><td></td><td style="background-color:#DDDDDD">.</td><td align="right">right in after</td></tr>
</table>
 
=== Character alignment methods ===
MkIV (starting in late June 2014) offers two methods for character alignment. The first, "number", attempts to identify the number from preceding and trailing text, align the number on the separator and separately vertically align preceding or trailing text by paddind in-between the number and the preceding/trailing text. This looks very nice when the preceding or trailing text is all of the same width (for example, a currency symbol or % sign), but will mis-align if the preceding or trailing text has varying widths. Number mode is the default for most separators, but can be forced by specifying <code>alignmentcharacter={number->-}</code>.
 
Note that the below examples will not render properly until the wiki supports this feature; this file shows the expected output. [[File:character_alignment_methods_example.pdf‎]]
 
<context source="yes" mode="mkiv">
% mode=mkiv
\setuppapersize[A5]
\bTABLE
\setupTABLE[c][1,2,3,4][alignmentcharacter={number->.},aligncharacter=yes,align=middle]
\bTABLEhead
\bTR
\bTH Same-Width Prefix \eTH \bTH Varying-Width Prefix \eTH
\bTH Same-Width Suffix \eTH \bTH Varying-Width Suffix \eTH
\eTR
\eTABLEhead
\bTABLEbody
\bTR \bTD \$1.00 \eTD \bTD \$1.00 \eTD \bTD 1.00\% \eTD \bTD 1.00\% \eTD \eTR
\bTR \bTD \$10.00 \eTD \bTD \$\$10.00 \eTD \bTD 10.00\% \eTD \bTD 10.00\%\% \eTD \eTR
\bTR \bTD \$1.0 \eTD \bTD \$1.0 \eTD \bTD 1.0\% \eTD \bTD 1.0\% \eTD \eTR
\bTR \bTD \$10.0 \eTD \bTD \$\$10.0 \eTD \bTD 10.0\% \eTD \bTD 10.0\%\% \eTD \eTR
\eTABLEbody
\eTABLE
</context>
 
In the above example the "varying-width" columns do not align on the alignment character. For these cases the "text" method is provided. The logic simpler&mdash;it does not attempt to pad space in-between the number and any preceding or trailing text, so the text will always align on the alignment character, but forgoes the attempt to vertically align preceding and trailing text. This is the default mode for the "-" separator, but can be forced by specifying <code>alignmentcharacter={text->.}</code>. The below example shows that all four columns align on the ".", but the "$" and "%" are no longer stacked.
 
<context source="yes" mode="mkiv">
% mode=mkiv
\setuppapersize[A5]
\bTABLE
\setupTABLE[c][1,2,3,4][alignmentcharacter={text->.},aligncharacter=yes,align=middle]
\bTABLEhead
\bTR
\bTH Same-Width Prefix \eTH \bTH Varying-Width Prefix \eTH
\bTH Same-Width Suffix \eTH \bTH Varying-Width Suffix \eTH
\eTR
\eTABLEhead
\bTABLEbody
\bTR \bTD \$1.00 \eTD \bTD \$1.00 \eTD \bTD 1.00\% \eTD \bTD 1.00\% \eTD \eTR
\bTR \bTD \$10.00 \eTD \bTD \$\$10.00 \eTD \bTD 10.00\% \eTD \bTD 10.00\%\% \eTD \eTR
\bTR \bTD \$1.0 \eTD \bTD \$1.0 \eTD \bTD 1.0\% \eTD \bTD 1.0\% \eTD \eTR
\bTR \bTD \$10.0 \eTD \bTD \$\$10.0 \eTD \bTD 10.0\% \eTD \bTD 10.0\%\% \eTD \eTR
\eTABLEbody
\eTABLE
</context>
 
Entering <code>\nocharacteralign</code> disables character alignment in a cell.
== Specifying the cell column ==
[[Category:XML]]
tt>\bTD
 
= An alignment issue =
 
In some cases the alignment of cell contents may not behave as you might expect. Here is an illustrative example. The following code
 
<context source=yes mode=mkiv text="gives us:">
\define[3]\Glyphbox
{\framed[frame=on,align=middle]\bgroup
#1\\
#2\\
#3%
\egroup}
 
\starttext
\setupTABLE[frame=on,align=middle]
\bTABLE
\bTR \bTD \Glyphbox{I}{a}{1} \eTD
\bTD \Glyphbox{I}{a}{1} \eTD
\eTR
\bTR \bTD \Glyphbox{III}{aaa}{111} \eTD
\bTD \Glyphbox{III}{aaa}{111} \eTD
\eTR
\eTABLE
\stoptext
</context>
 
Note that in the first row the cells are not middle-aligned. As Wolfgang Schuster pointed out on the list, we need *two* things to fix this:
 
1. You need <tt>\dontleavehmode</tt> in front of the <tt>\framed</tt>.
2. You need <tt>\setupTABLE[start][..,..=..,..]</tt> because <tt>\bTABLE</tt> sets a default value for the align key which can’t be overwritten with a simple <tt>\setupTABLE[..,..=..,..]</tt>.
 
Implementing this <context source=yes mode=mkiv text="we now get the following correct output with centered cells in the first row:">
\define[3]\Glyphbox
{\dontleavehmode
\framed[frame=on,align=middle]\bgroup
#1\\
#2\\
#3%
\egroup}
 
\starttext
\setupTABLE[start][frame=on,align=middle]
\bTABLE
\bTR \bTD \Glyphbox{I}{a}{1} \eTD
\bTD \Glyphbox{I}{a}{1} \eTD
\eTR
\bTR \bTD \Glyphbox{III}{aaa}{111} \eTD
\bTD \Glyphbox{III}{aaa}{111} \eTD
\eTR
\eTABLE
\stoptext
</context>
 
= Footnotes in TABLEs =
 
From this conversation on the mailing list[https://mailman.ntg.nl/pipermail/ntg-context/2017/089097.html]. In order to get global footnotes printing after tables (without using the local footnotes trick):
 
<texcode>
Text\footnote{Normal Footnote}
\bTABLE[split=repeat,align=normal]
\bTR\bTD Something\postponenotes\footnote[x]{bla bla}\eTD\eTR
\bTR\bTD Foo\note[x] \eTD\eTR
\eTABLE
\flushnotes
More Text\footnote{Another Normal Footnote}
</texcode>
<context mode=mkiv source=no>
\setupnote[footnote][location=text]
\setupnotations[alternative=serried]
\starttext
Text\footnote{Normal Footnote}
\bTABLE[split=repeat,align=normal]
\bTR\bTD Something\postponenotes\footnote[x]{bla bla}\eTD\eTR
\bTR\bTD Foo\note[x] \eTD\eTR
\eTABLE
\flushnotes
More Text\footnote{Another Normal Footnote}
Note that the context wiki is eating the footnote numbers, but that they are there anyways.
\placefootnotes
\stoptext
 
 
</context>
4

edits

Navigation menu