Changes

Jump to navigation Jump to search
14,830 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 “natural tables” or (also known as “automatic tables.” I'd call it or “HTML tables,” because it's very similar to them). They're are especially suited for [[XML]] conversions. See the [[manual:enattab.pdf|enattab.pdf]] manual for many examples.
Beware: every element must To place a table use <tt>\b</tt> ... <tt>\e</tt>! You find a lot of samples in [[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/NaturalTables.pdf Use of natural tables]
<texcode>
\setupTABLE[row][odd][background=color,backgroundcolor=red, width=.2\textwidth]placetable{Caption}{\bTABLE[split=yes]\bTR \bTD[nr=3] 1 \eTD \bTD[nc=2] 2/3 \eTD \bTD[nr=3] 4 \eTD \eTR\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR\bTR \bTD[nc=3] 1/2/3 One \eTD \bTD 4 two \eTD \eTR\bTR \bTD 1 \eTD \bTD 2 \eTD \bTD 3 One \eTD \bTD 4 two \eTD \eTR\eTABLE}
</texcode>
You get automatic page breaking with the option <tt>[split=yes]</tt>.A more elaborate example:
The sample looks like this:<context source=yes>This is our red-coloured table.\setupcolors[state=start]
<context>
\setupTABLE[row][odd][background=color,backgroundcolor=red, width=.2\textwidth]
\bTABLE[split=yes]% allow splitting over page boundaries \bTR \bTD[nr=3] 1 \eTD \bTD[nc=2] 2/3 \eTD \bTD[nr=3] 4 \eTD \eTR \bTR \bTD 2 \eTD \bTD 3 \eTD \eTR \bTR \bTD 2 \eTD \bTD 3 \eTD \eTR \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>
 
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:coretabl-ntb.texmkiv|coretabl-ntb.texmkiv]]
If you must <b>split</b> a natural table over several pages, you can
simply do this by adding <tt>\setupTABLE[split=yes]</tt> to your TABLE
definition. An other Another way is to define it right at the TABLE start
by adding the parameter <tt>[split=yes]</tt> (see example).
However,
{{cmd|startlinecorrection}}
can lead to unpredictable vertical spaces between rows [http://archive.contextgarden.net/message/20100912.112605.8a1aaf13.en.html].
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.This is a known limitation due to the complicated calculation of remaining space on the page.That won't become better before this calculations are newly written in Lua. (Said Hans on 2010-09-24.)
The following standalone example deals with all the mentioned aspects of natural tables.
\eTABLE
\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 =
 
... just work (at least in luaTeX and not here...). See the following example.
 
<texcode>
\starttext
\startcolumns[n=3]
\bTABLE
\dorecurse{21}
{\bTR \bTD a\eTD \bTD b \eTD \eTR}
\eTABLE
\stopcolumns
\stoptext
</texcode>
See also [[m-database|the database module]]!
 
and [http://dl.contextgarden.net/myway/csv.pdf Creating Tables using CSV (Comma-separated values)] by Mojca Miklavec
 
<!-- Maybe some other place or a separate page is more appropriate for this section -->
<context>
\setuppapersize[A5]
 
% Iterate over all the lines of text captured with \obeylines active
% command to call is first argument, is not called for empty lines
* quoted strings may contain commas themselves (which means writing a custom version of \processcommalist instead).
See also {{howtocmd|processseparatedlist}} HH: there is:  <texcode>\processseparatedlist[list][separator]\command</texcode> What about separating the values using tabs?.
= Designing complex TABLEs =
<context>
\setuppapersize[A5]\setupTABLE[r][each][height=1cm0.5cm]
\setupTABLE[c][each][width=1cm]
\bTABLE
<context>
\setuppapersize[A5]\setupTABLE[r][each][height=1cm0.5cm]
\setupTABLE[c][each][width=1cm]
\setupTABLE[r][1][height=0cm,frame=off]
</td><td>
<context>
\setuppapersize[A5]
\setupTABLE[c][each][align={middle,lohi},frame=off]
\setupTABLE[r][2,3,4,5,6][height=10.0cm5cm]
\setupTABLE[r][2,4][topframe=on]
\setupTABLE[c][1,2,3][rightframe=on]
<context>
\setuppapersize[A5]
\setupTABLE[c][each][align={middle,lohi},frame=off]
\setupTABLE[r][2,3,4,5,6][height=10.0cm5cm]
\setupTABLE[r][1,3][bottomframe=on]
\setupTABLE[c][1,2,3][rightframe=on]
<context>
\setuppapersize[A5]
\setupTABLE[c][each][align={middle,lohi},frame=off]
\setupTABLE[r][2,3,4,5,6][height=10.0cm5cm]
\setupTABLE[r][2,4][topframe=on]
\setupTABLE[c][1,2,3][rightframe=on]
</texcode>
'''Beware'''== 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 drawingcells using a background and/or a frame. Note that offsets can be uniform <tt>distance[offset=dimension]</tt> parameter is only available from ,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 next release 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 rowand not for the entire table; otherwise, it would enter into thecalculation of the cell dimensions (in and interplay with other parameterssuch as <tt>core-ntb-newcolumndistance</tt>).tex 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 ==
 Drawing bold lines around a cell is done using the<tt>[rulethickness=''dim'']<table/tt>key on a cell. The thicker rules willoffset the text inside the cell both downwards and sideways, so careshould be taken that the cell's increased rulethickness is offset by anequal decrease in offset. <tr valigncontext source="topyes" text="produces"><td><texcode>\setupTABLE[row][each][rulethickness=.25pt,offset=\dimexpr1mm+1.75pt]
\bTABLE
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2/3 \eTD \eTR
\bTR \bTD 2 \eTD \bTD 2 \eTD \bTD 3 \eTD \eTR
\bTR \bTD 2 \eTD \bTD[rulethickness=2pt,offset=1mm] 2 \eTD \bTD 3 \eTD \eTR
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 4 \eTD \eTR
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2 \eTD \eTR
\eTABLE
</texcodecontext== Rules == === Example: an invoice with thick rules === </tdcontext source="yes">\setuppapersize[A5]{\bfa Invoice}\switchtobodyfont[6pt]\blank\bTABLE \setupTABLE[frame=off,offset=1mm] \setupTABLE[row][*][height=7.25mm] \setupTABLE[column][1,2] [width=20mm,offset=\dimexpr1mm+2pt,align=flushleft] \setupTABLE[column][3,4,5][width=20mm,offset=\dimexpr1mm+2pt,align=flushright] \bTR[bottomframe=on, rulethickness=2pt,offset=1mm] \bTD\bf Date \eTD \bTD\bf Description \eTD \bTD\bf Quantity \eTD \bTD\bf Price \eTD \bTD\bf Total \eTD \eTR \bTR[bottomframe=on,rulethickness=.25pt] \bTD 05-01-2010 \eTD \bTD Element 1 \eTD \bTD 10.0 \eTD \bTD 6.00 \eTD \bTD 60.00 \eTD \eTR \bTR[bottomframe=on,rulethickness=.25pt] \bTD 05-01-2010 \eTD \bTD Element 2 \eTD \bTD 2.0 \eTD \bTD 3.00 \eTD \bTD 6.00 \eTD \eTR \bTR[topframe=on,rulethickness=2pt,offset=1mm] \bTD[nx=3] \eTD \bTD[align=flushleft] Subtotal \eTD \bTD 66.00 \eTD \eTR \bTR[offset=\dimexpr1mm+2pt] \bTD[nx=3] \eTD \bTD[align=flushleft] VAT 19\% \eTD \bTD 12.54 \eTD \eTR \bTR \bTD[nx=3] \eTD \bTD[align=flushleft] \bf Total \eTD \bTD 78.54 \eTD \eTR\eTABLE<td/context=== Rules with different thickness === There is only one value for all four borders. However, MetaPost can be used as a workaround until the separate "rulethickness" values are implemented. The following example (mkiv only!) by Wolfgang Schuster shows a table using MetaPost for the rules: <contextsource=yes mode=mkiv text="gives:">\startuseMPgraphic{tableborders} draw leftboundary OverlayBox withpen pensquare scaled \frameddimension {leftrulethickness} ;draw rightboundary OverlayBox withpen pensquare scaled \frameddimension {rightrulethickness} ;draw topboundary OverlayBox withpen pensquare scaled \frameddimension {toprulethickness} ;draw bottomboundary OverlayBox withpen pensquare scaled \frameddimension{bottomrulethickness} ; clip currentpicture to OverlayBox leftenlarged (\frameddimension {leftrulethickness}/2) rightenlarged (\frameddimension {rightrulethickness}/2) topenlarged (\frameddimension {toprulethickness}/2) bottomenlarged (\frameddimension{bottomrulethickness}/2) ; setbounds currentpicture to OverlayBox ; \stopuseMPgraphic \defineoverlay[tableborders][\useMPgraphic{tableborders}] \startsetups tableborders \setupTABLE [ background={color,tableborders}, frame=off, backgroundoffset=0pt, leftrulethickness=\framedparameter{rulethickness}, rightrulethickness=\framedparameter{rulethickness}, toprulethickness=\framedparameter{rulethickness}, bottomrulethickness=\framedparameter{rulethickness}] \setupTABLE[row] [odd] [backgroundcolor=lightgray]\setupTABLE[row] [first][backgroundcolor=gray,bottomrulethickness=2pt]\setupTABLE[row] [last] [toprulethickness=2pt,bottomrulethickness=2pt]\setupTABLE[first][last] [leftrulethickness=2pt]\setupTABLE[last] [last] [rightrulethickness=2pt] \stopsetups \starttext 
\bTABLE
\dorecurse{7}{\bTR \dorecurse{3}{\bTD #1 \eTD \bTD -##1 \eTD \bTD 2/3 \eTD }\eTR}\bTR eTABLE \bTD 2 \eTD \bTD 2 \eTD \bTD 3 \eTD \eTRblank \bTR \bTD 2 \eTD \bTDbTABLE[rulethicknesssetups=2pttableborders] 2 \eTD \bTD 3 \eTD \eTRdorecurse{7}{\bTR \bTD 1 \eTD dorecurse{3}{\bTD #1 \eTD \bTD 4 \eTD \eTR\bTR \bTD -##1 \eTD \bTD 1 \eTD \bTD 2 \eTD }\eTR}
\eTABLE
 
\stoptext
</context>
 
See the corresponding thread on the list: [http://www.ntg.nl/pipermail/ntg-context/2011/058549.html rules with different thickness]
 
=== Thick bottom rules ===
 
This is a simplified version of the example above (corresponding mailing thread - [http://www.ntg.nl/pipermail/ntg-context/2012/069541.html TABLE: header with a thick bottom line]).
 
<context source=yes mode=mkiv text="Gives:">
\startuseMPgraphic{MP:thickBtm}
draw bottomboundary OverlayBox withpen pensquare scaled \frameddimension{bottomrulethickness};
clip currentpicture to OverlayBox;
setbounds currentpicture to OverlayBox;
\stopuseMPgraphic
 
\defineoverlay[OL:thickBtm][\useMPgraphic{MP:thickBtm}]
 
\starttext
\bTABLE
\setupTABLE[align=middle]
\setupTABLE[header][background={OL:thickBtm},bottomrulethickness=4pt]
\setupTABLE[row][4][background={OL:thickBtm},bottomrulethickness=2pt]
%
\bTABLEhead\bTR\dorecurse{3}{\bTH#1\eTH}\eTR\eTABLEhead
\bTABLEbody\dorecurse{6}{\bTR\dorecurse{3}{\bTD#1-##1\eTD}\eTR}\eTABLEbody
\eTABLE
\stoptext
</context>
 
=== Diagonal rules ===
 
Sometimes a diagonal rule is required in the top left corner cell of a table to create two fields, one for the left column and one for the top row.
 
 
<context mode="mkiv" source="yes" text="Gives:">
\startuseMPgraphic{DiagonalRule}
rulethickness := \frameddimension{rulethickness};
 
drawoptions(
withpen pencircle scaled rulethickness
withcolor \MPcolor{\framedparameter{framecolor}});
 
pair leftcorner, rightcorner;
leftcorner := (rulethickness, \overlayheight-rulethickness);
rightcorner := (\overlaywidth-rulethickness, rulethickness);
 
draw leftcorner -- rightcorner;
\stopuseMPgraphic
 
\defineoverlay
[DiagonalRule]
[\useMPgraphic{DiagonalRule}]
 
\define[2]\DiagonalLabel{%
\setuptabulate [after={\blank[\frameddimension{offset}]}]
\starttabulate [|p|r|]
\NC \NC #2 \NC\NR
\NC #1 \NC \NC\NR
\stoptabulate
}
 
\starttext
\setupTABLE [row] [1] [width=2cm]
\bTABLE
\bTR
\bTD [background=DiagonalRule]
\DiagonalLabel{Foo}{Bar}
\eTD
\bTD Second \eTD
\bTD Third \eTD
\eTR
\bTR
\bTD Alpha \eTD
\bTD Beta \eTD
\bTD Gamma \eTD
\eTR
\eTABLE
\stoptext
</context>
 This solution has (at least) one caveat: Because the firsttabulate column is set in paragraph mode, it will eat up as muchspace as <em>possible</tdem>, in contrast to occupying as much space as</trem>necessary</tableem>. That is why the width of the column has to be setexplicitly.
== Using character alignment ==
</td><td>
<context>
\setuppapersize[A5]
\bTABLE
\setupTABLE[column][1][align=right]
</td></tr></table>
You'll note that the final line, because it has no <code>. </code> in the number, gets aligned under the right-hand side of the numbers. In most circumstances you would want such a number aligned with the left-hand set of digits. To so do, issue the following command in your preamble:
<texcode>
<context>
\setuppapersize[A5]
\chardef\characteralignmentmode=2
\bTABLE
<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 ==
Here is an example using the "n" option:
<texcodecontext source=yes>\bTABLE[width=3em]\bTR\bTD d1 \eTD\bTDsetuppapersize[n=2A5] d2 \eTD\bTD[n=5] d5 \eTD\bTD[n=7] d7 \eTD\eTR\bTR\bTD f1 \eTD\bTD[n=4] f4 \eTD\bTD[n=5] f5 \eTD\bTD[n=7] f7 \eTD\eTR\eTABLE</texcode> It looks like: <context>
\bTABLE[width=3em]
\bTR\bTD d1 \eTD\bTD[n=2] d2 \eTD\bTD[n=5] d5 \eTD\bTD[n=7] d7 \eTD\eTR
Here is an example using the "m" option:
<texcodecontext source=yes>\bTABLE[width=3em]\bTR\bTD d1 \eTD\bTDsetuppapersize[m=2A5] d2 \eTD\bTD[m=5] d5 \eTD\bTD[m=7] d7 \eTD\eTR\bTR\bTD f1 \eTD\bTD[m=4] f4 \eTD\bTD[m=5] f5 \eTD\bTD[m=7] f7 \eTD\eTR\eTABLE</texcode> It looks like: <context>
\bTABLE[width=3em]
\bTR\bTD d1 \eTD\bTD[m=2] d2 \eTD\bTD[m=5] d5 \eTD\bTD[m=7] d7 \eTD\eTR
For a different approach for round corners and colored background follow the text after this example.
It is possible to round the corners of the table if you turn off the main frame of the table and frame the table in [[{{cmd:framed|\framed]]}}. Compare two different approaches in the first and second example.
You can't color the background of the table with round corners unless the frame rulethickness is not big enough to cover the rectangular corners of the background (second example). Well, you can if you frame the table twice. Once in the thick white frame and then in the thin frame with negative offset and slightly smaller corner radius (third example). Be aware of other complications -- notice that the thick white frame is still visible in the text above it.
\setupTABLE[background=color,backgroundcolor=yellow]
\setupframed[framecolor=darkgreen]
 
\defineparagraphs[ThreeCols]
 
\startThreeCols
First
\StartTable
\bTABLE \bTR \bTD test \eTD \bTD test \eTD \eTR \bTR \bTD test \eTD \bTD test \eTD \eTR \bTR \bTD test \eTD \bTD test \eTD \eTR \eTABLE
\StopTable
 
\nextThreeCols
Second
\setupTABLE[column][last] [rightframe=off]
\framed[strut=no,corner=round,offset=.5\linewidth,,rulethickness=1mm]\bgroup
\bTABLE \bTR \bTD test \eTD \bTD test \eTD \eTR \bTR \bTD test \eTD \bTD test \eTD \eTR \bTR \bTD test \eTD \bTD test \eTD \eTR \eTABLE
\egroup
 
\nextThreeCols
Third
\setupTABLE[column][first][leftframe=off]
\setupTABLE[column][last] [rightframe=off]
\framed[strut=no,corner=round, radius=1.4mm,offset=-1mm,,rulethickness=.1mm]\bgroup \framed[strut=no,corner=round, radius=1.5mm,offset=0mm,,rulethickness=1mm,framecolor=white]\bgroup \bTABLE \bTR \bTD test \eTD \bTD test \eTD \eTR \bTR \bTD test \eTD \bTD test \eTD \eTR \bTR \bTD test \eTD \bTD test \eTD \eTR \eTABLE \egroup
\egroup
 
\stopThreeCols
\stoptext
<context source="yes">
\setuppapersize[A5]
\starttext
\setupcolors[state=start]
</context>
== Other options == Some other useful options that were not covered above:* <tt>align=yes</tt> will align the text both left and right justified* <tt>loffset</tt>, <tt>roffset</tt>, <tt>toffset</tt>, <tt>boffset</tt> can be used in addition to <tt>offset</tt> to specify cell content offsets in each direction separately, see also {{cmd|framed}} =TABLEs with old table syntax=
From the mailing list in March 2009, by Wolfgang Schuster and Hans Hagen:
\dodoubleempty\parseTD#1\eTD\NC}
</texcode>
 
This is now part of the core as the [[source:tabl-nte.tex|NTE module]]. Quoting its internal documentation:
 
This module is suggested by Wolfgang Schuster who also prototyped it and came up with the rationale:
 
This module provides an easy way to use natural in a similiar way as the older table module (based on the [[TABLE]] macros) and the newer [[tabulate]] module.
 
You can see the advantage in the following table, once created with the new macros and once with the normal macros provided with the natural table module.
 
Let us start with the original macros:
 
<texcode>
\bTABLE
\bTR
\bTD Text 1 \eTD
\bTD Text 2 \eTD
\eTR
\bTR
\bTD Text 3 \pasteeTD
\bTD Text 4 \eTD
\eTR
\eTABLE
</texcode>
 
Watch how the new macros use less code:
 
<texcode>
\startTABLE
\NC Text 1 \NC Text 2 \NC\NR
\NC Text 3 \NC Text 4 \NC\NR
\stopTABLE
</texcode>
 
The actual code differs from the prototype that it does not need to collect whole rows and parse them but looks ahead instead.
 
= Get current row/column number =
See for example here: [[Command/currentTABLErow]]
[[Category:Tables]]
[[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