Changes

Jump to navigation Jump to search
19,381 bytes added ,  09:05, 22 August 2017
m
no edit summary
< [[Tables Overview]] | [[XML]] >
This mighty table mode is called &ldquo;natural tables&rdquo; or &ldquo;automatic tables.&rdquo; I'd call it &ldquo;HTML tables,&rdquo; because it's very similar to them. They're especially suited for [[XML]] conversions.=Introduction=
BewareThe preferred way to typeset tables is to use what are called &ldquo;natural tables&rdquo; (also known as &ldquo;automatic tables&rdquo; or &ldquo;HTML tables&rdquo;). They are especially suited for [[XML]] conversions. See the [[manual: every element must use <tt>\b</tt> enattab.pdf|enattab.pdf]] manual for many examples. <tt>\e</tt>!
You find To place a lot of samples in [httptable use://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://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 want to must <b>split</b> your 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 startby adding the parameter <tt>[split=yes]</tt> (as in 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}} and {{cmd|eTABLEhead}})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 ofyour multipage table. Please take account of the fact, that the examplehead cells are enclosed by {{cmd|bTH}} and {{cmd|eTH}} (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 headerbetween {{cmd|bTABLEnext}}...{{cmd|eTABLEnext}},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}} and{{cmd|eTABLEfoot}}. It defines the concluding row of your natural table.
The content of '''Beware:''' Split tables often begin not on the <b>table head</b>page (all between <tt>\bTABLEhead<or in the column, if you use them) where they ''could'' start, but on/tt> and <tt>\eTABLEhead</tt>)is printed at in the beginning of every new page that contains parts ofyour multipage tablenext one.In case you want This is a known limitation due to use different table headers for the beginning complicated calculation of remaining space on the table and thepage.following splitted parts you can do That won't become better before this by defining an <b>alternate header</b>calculations are newly written in Lua.Just add <tt>\bTABLEnext</tt>(Said Hans on 2010-09-24...<tt>\eTABLEnext</tt> with the wanted header layoutright after your normal head definition. This defines the alternate (maybe less verbose)header for all but the first part.
The table footer is defined between <tt>\bTABLEfont</tt> andfollowing standalone example deals with all the mentioned aspects of natural tables.Just <tti>\eTABLEfontcopy&paste</tti>it as a starting point for further experiments...
<texcode>
\bTABLEstarttext \setupcolors[splitstate=yesstart] %setup for all cells\setupTABLE[r][each][style=\tfx\it, align=center] % here starts the definition of the setup table head\setupTABLE[r][first] [background=color, backgroundcolor=yellow]% IMPORTANT: use setup table footer\eTH ... setupTABLE[r][last] [style=bold, background=color, backgroundcolor=green] \eTH to enclose the bTABLE[split=repeat,option=stretch]% head cellson every page, stretch columns
%
% IMPORTANT: use \bTH ... \eTH to enclose the head|next cells
\bTABLEhead
\bTR
\bTH _your_table_head_ column 1 head1 \eTH \bTH _your_table_head_ column 2 head2 \eTH \bTH _your_table_head_ column 3 head3 \eTH
\eTR
\eTABLEhead
%
\bTABLEnext % setup for next table head
\bTR [background=color,backgroundcolor=cyan]
\bTH next1 \eTH
\bTH next2 \eTH
\bTH next3 \eTH
\eTR
\eTABLEnext
%
% the table body (main part)
%
\bTABLEbody
%
\dorecurse{100}{% 100 rows
\bTR
\bTC _your_table_body_ row 1, column 1 body body body body body \eTC \bTC _your_table_body_ row 1, column 2 body body body body body \eTC \bTC _your_table_body_ row 1, column 3 \eTC\eTR%...%... (the rest of your multipage table)%...\bTR \bTC _your_table_body_ row n, column 1 \eTC \bTC _your_table_body_ row n, column 2 \eTC \bTC _your_table_body_ row n, column 3 body body body body body \eTC
\eTR
}%
%
\eTABLEbody
%
% the table foot
%
\eTABLEfootbTABLEfoot
\bTR
\bTC _your_table_foot_ column 1 foot1 \eTC \bTC _your_table_foot_ column 2 foot2 \eTC \bTC _your_table_foot_ column 3 foot3 \eTC
\eTR
\eTABLEfoot
\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>
== Creating tables from CSV data (Comma Separated Values) == 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 ==
Everything is easy when a simple grid is enough. Unfortunately, this
<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>\setuppapersize[A5]
\bTABLE[width=3em]
\bTR\bTD d1 \eTD\bTD[n=2] 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
</texcodecontext>
It looks likeHere is an example using the "m" option:
<contextsource=yes>\setuppapersize[A5]
\bTABLE[width=3em]
\bTR\bTD d1 \eTD\bTD[nm=2] d2 \eTD\bTD[nm=5] d5 \eTD\bTD[nm=7] d7 \eTD\eTR\bTR\bTD f1 \eTD\bTD[nm=4] f4 \eTD\bTD[nm=5] f5 \eTD\bTD[nm=7] f7 \eTD\eTR\eTABLE</context> == Round corners == 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}}. 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. <context source="yes">\starttext\setupcolors[state=start] %\showstruts\setupTABLE[background=color,backgroundcolor=yellow]\setupframed[framecolor=darkgreen] \defineparagraphs[ThreeCols] \startThreeCols First \def\StartTable {\setupTABLE[row] [first][topframe=off]% \setupTABLE[row] [last] [bottomframe=off]% \setupTABLE[column][first][leftframe=off]% \setupTABLE[column][last] [rightframe=off]% \framed[strut=no,corner=round,offset=.5\linewidth] \bgroup} \def\StopTable {\egroup} \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[row] [first][topframe=off]\setupTABLE[row] [last] [bottomframe=off]\setupTABLE[column][first][leftframe=off]\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[row] [first][topframe=off]\setupTABLE[row] [last] [bottomframe=off]\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> From 2006-10-11 on, ConTeXt contains one more mechanism for round corners. Watch the example: <context source="yes">\setuppapersize[A5]\starttext\setupcolors[state=start]\setupTABLE [y] [first][background=color,backgroundcolor=blue,frame=off,bottomframe=on,topframe=on,framecolor=white]\setupTABLE [first][first][backgroundcorner=2,corner=10,frame=on]\setupTABLE [last] [first][backgroundcorner=4,corner=12,frame=on]\setupTABLE [row] [each] [background=color,backgroundcolor=blue,frame=on,framecolor=white]\setupTABLE [first][2] [corner=8]\setupTABLE [last] [2] [corner=5]\setupTABLE [first][last] [corner=7]\setupTABLE [last] [last] [corner=6] \bTABLE[frame=off,align=middle]\bTR \bTD one \eTD \bTD two \eTD \bTD three \eTD \eTR\bTR \bTD first \eTD \bTD second \eTD \bTD third \eTD \eTR\bTR \bTD alpha \eTD \bTD beta \eTD \bTD gamma \eTD\eTR
\eTABLE
\stoptext
</context>
Here == 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: <texcode>\def\startTABLE {\dosingleempty\dostartTABLE} \def\dostartTABLE[#1]% {\bgroup \bTABLE[#1]% \let\NC\doTABLENC \let\NR\doTABLENR \let\bTR\relax \let\bTD\relax \let\bTH\relax \let\bTN\relax} \def\stopTABLE {\eTABLE \egroup} \newconditional\inTABLEnc \unexpanded\def\doTABLENR {\eTR \setfalse\inTABLEnc} \unexpanded\def\doTABLENC {\futurelet\next\dodoTABLENC} \def\dodoTABLENC {\ifx\next\doTABLENR \else \expandafter\dododoTABLENC \fi} \long\def\dododoTABLENC#1\NC{\ifconditional\inTABLEnc\else\settrue\inTABLEnc\parseTR[][]\fi \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 example using 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 "m" optionoriginal macros:
<texcode>
\bTABLE[width=3em] \bTR \bTD d1 Text 1 \eTD \bTD[m=Text 2] d2 \eTD\bTD[m=5] d5 \eTD\bTD[m=7] d7 \eTD \eTR \bTR \bTD f1 Text 3 \eTDpasteeTD \bTD[m=Text 4] f4 \eTD\bTD[m=5] f5 \eTD\bTD[m=7] f7 \eTD \eTR
\eTABLE
</texcode>
It looks likeWatch 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 <contextsource=yes mode=mkiv text="gives us:">\bTABLEdefine[3]\Glyphbox {\framed[frame=on,align=middle]\bgroup #1\\ #2\\ #3% \egroup} \starttext\setupTABLE[widthframe=3emon,align=middle]\bTABLE\bTR \bTD \Glyphbox{I}{a}{1} \eTD \bTD \Glyphbox{I}{a}{1} \eTD \eTR\bTR\bTD d1 \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][m..,..=2..,..] d2 </tt> because <tt>\eTDbTABLE</tt> sets a default value for the align key which can’t be overwritten with a simple <tt>\bTDsetupTABLE[m..,..=..,..]</tt>. Implementing this <context source=5yes mode=mkiv text="we now get the following correct output with centered cells in the first row:">\define[3] d5 \eTDGlyphbox {\dontleavehmode \bTDframed[mframe=7on,align=middle] d7 \eTDbgroup #1\\ #2\\ #3% \egroup} \starttext\setupTABLE[start][frame=on,align=middle]\eTRbTABLE\bTR\bTD f1 \Glyphbox{I}{a}{1} \eTD \bTD[m=4] f4 \Glyphbox{I}{a}{1} \eTD\eTR\bTR \bTD[m=5] f5 \Glyphbox{III}{aaa}{111} \eTD \bTD[m=7] f7 \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\flushnotesMore Text\footnote{Another Normal Footnote}</texcode><context mode=mkiv source=no>\setupnote[footnote][Category:Tableslocation=text]\setupnotations[alternative=serried]\starttextText\footnote{Normal Footnote}\bTABLE[split=repeat,align=normal]\bTR\bTD Something\postponenotes\footnote[Category:XMLx]{bla bla}\eTD\eTR\bTR\bTD Foo\note[x]\eTD\eTR\eTABLE\flushnotesMore 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