Changes

Jump to navigation Jump to search
5,097 bytes added ,  15:06, 25 August 2021
m
Convert to an HTML table
< [[Tables Overview]] | [[tabulateTabulate]] | [[Tables]] >
This is ConTeXts oldest table module. It uses the same formatting as [[tabulateTabulate]] (see [[Tables Overview]]).
This mode is based on Michael Wichura's TaBlE package for PlainTeX. The official manual for it is commercial (about 40 USD), see [http://www.pctex.com/books.html PCTeX] -- but note that the TaBlE manual only talks about the original syntax, which does not use <{{cmd>|NC</cmd>}}, <{{cmd>|HL</cmd> }} cum suis.
The only ConTeXt docs are in [[manual:ms-cb-en.pdf|ConTeXt - an excursion]]. There is also two introductory articles in tugboat [http://tug.org/TUGboat/Articles/tb28-3/tb90mahajan.pdf ConTeXt basics for users: Table macros] [http://www.tug.org/TUGboat/Articles/tb29-1/tb91mahajan.pdf Table macros II] by Aditya Mahajan (2007 and 2008).
== Basic Commands ==
\stoptable
</context>
</td></tr></table>
* You get vertical lines (rules), if you use <{{cmd>|VL</cmd> }} instead of <{{cmd>|NC</cmd>}}.* Better use <{{cmd>|SR</cmd>}}, <{{cmd>|FR</cmd>}}, <{{cmd>|MR</cmd>}}, <{{cmd>|LR</cmd> }} instead of <{{cmd>|NR</cmd>}}.* You can also use <{{cmd>|AR</cmd> }} instead of <{{cmd>|SR</cmd>}}, <{{cmd>|FR</cmd>}}, <{{cmd>|MR</cmd> }} and <{{cmd>|LR</cmd> }} (AR for automatic row).* You can leave out the <{{cmd>|NC</cmd> }} before the "row" command, but not if you use <{{cmd>|AR</cmd> }} in a last or single row (see example).* You can influence the table with <{{cmd>|setuptables</cmd>.* There are also <cmd>BL</cmd> and <cmd>CL</cmd> for colored backgrounds, see below}}.
==Column Definition==
The table is defined by the template enclosed in square brackets after <{{cmd>|starttable</cmd>}}. The template has the form<tt>|keys for the first column|keys for the second column|...|keys for the last column|</tt>. Please note that the each column is surrounded by <tt>|</tt> signs. These are necessary. The formatting keys for each column can be a choice of {| class="wikitable" ! Key ! Meaning |- ! colspan="2" | Primitive Keys |- | <code>a{<em>tokens</em>}</code> | Adds <code><em>tokens</em></code> <em>after</em> the column content |- |- | <code>b{<em>tokens</em>}</code> | Adds <code><em>tokens</em></code> <em>before</em> the column content |- | <code>\{</code> | Enclose the column in braces (grouping) |- | <code>*{<em>n</em>}{<em>keys</em>}</code> | Equivalent to repeating the formatting keys <code><i>keys</i></code> <code><i>n</i></code> times |- ! colspan="2" | Positioning Keys |- | <code>\LeftGlue</code> | Specifies the left glue to be used before the column |- | <code>\RightGlue</code> | Specifies the right glue to be used after the column |- | <code>l</code> | left-aligned column |- | <code>c</code> | centered column |- | <code>r</code> | right-aligned column |- | <code>p(<em>width</em>)</code> | Set each cell as a paragraph |- | <code>s(<em>width</em>)</code> | Specify the inter-column width |- | <code>w</code> | Set minimum column width |- | <code>k</code> | Insert a kern both left and right of the column |- | <code>i</code> | Add a kern to the left of the column |- | <code>j</code> | Add a kern to the right of the column |- ! colspan="2" | Numeric and Math Item Keys |- | <code>n</code> | Numeric item not in math mode |- | <code>N</code> | Numeric item in math mode |- | <code>m</code> | Each cell is in (inline) math mode. Equivalent to <code>b$ a$</code> |- | <code>M</code> | Each cell is in display math mode. Equivalent to <code>\{b{$\displaystyle}a$}</code> |- | <code>\m</code> | Equivalent to 1 <code>l b{{}}m</code> |- | <code>\M</code> | Equivalent to 1 <code>l b{{}}M</code> |- ! colspan="2" | Style Keys |- | <code>f\<em>command</em></code> | Set font according to following <code><em>command</em></code> |- | <code>B</code> | Bold. Equivalent to <code>f\bf</code> |- | <code>I</code> | Italic. Equivalent to <code>f\it</code> |- | <code>S</code> | Slanted. Equivalent to <code>f\sl</code> |- | <code>R</code> | Roman. Equivalent to <code>f\rm</code> |- | <code>T</code> | Teletype. Equivalent to <code>f\tt</code> |- | <code>C</code> | Color. Use it in combination with <code>\{</code> (e.g. <code>\{C{<em>red</em>}</code>) |- ! colspan="2" | Tabskip Keys |- | <code>s</code> | Set the tabskip to the right of this column and of all following columns up to the next <code>s</code> or <code>o</code> key |- | <code>o</code> | Set the tabskip to the right of this column only |- |} === Column definition examples===; <code>|l|</code> : a left aligned column, as wide as necessary; <code>|lw(2cm)|</code> : a left aligned column of at least 2 cm width; <code>|p(2cm)|</code> : a centered(!) paragraph of 2 cm width; <code>|lp(.5\textwidth)|</code> : a left aligned paragraph of specified width; <code>|rp(.5\textwidth)|</code> : a right aligned paragraph of specified width; <code>|cp(.5\textwidth)|</code> : a center aligned paragraph of specified width; <code>|xp(.5\textwidth)|</code> : a justified paragraph of specified width {{todo|add more examples of column definitions}} ==Column Spans== It's possible to create columnspans (i.e. cells that span more than one column) with the command {{cmd|use|{<i>N</i>}}} where ''N'' is the number of columns spanned by the cell. It's often necessary to use {{cmd|ReFormat|[<i>new keys</i>]{}}} to reformat this specific cell according to the ''new keys''.
 <table width="100%" cols="2"><tr valign="top"><td><contexttexcode>\switchtobodyfont[ss, 8pt]\starttable[s(0pt)|lls(10pt)|lprs(.5\textwidth0pt)|]\HL\NC \use{2}\ReFormat[cB]{Spanning head} \SR\HL\NC \Use{2}[cB]{Spanning head} \SR % slightly shorted
\HL
\NC left text \bf Key VL right column text \NC \AR\NC new row \VL new row \NC \AR\NC left text \VL \bf Meaning ReFormat[l]{reformatted} \NC \SRAR
\HL
\NC \NC Primitive Keys use{2}Spanning entry \SR
\HL
\NC \type{a{tokens}}\VL Adds \type{tokens} {\em after} the column content\ARstoptable</texcode></td><td>\NC \type{b{tokens}}\VL Adds \type{tokens} '''before''' the column content\AR<context>\NC {\tt \backslash\{ } \VL Enclose the column in braces \ARsetuppapersize[A5]\NC \type{*{n}{keys}}\VL Equivalent to repeating the formatting keys \type{keys} \type{n} times\NC\LRstarttable[s(0pt)|ls(10pt)|rs(0pt)|]
\HL
\NC \NC Positioning Keysuse{2}\ReFormat[cB]{Spanning head} \SR
\HL
\NC \typeUse{\LeftGlue} \VL Specifies the left glue to be used before the column\AR\NC \type{\RightGlue} \VL Specifies the right glue to be used after the column\AR\NC \type{l2} \VL left-aligned column\AR\NC \type{c} \VL centered column\AR\NC \type[cB]{rSpanning head} \VL right-aligned column\AR\NC \type{p(width)} \VL Set each cell as a paragraph\AR\NC \type{w} \VL Set minimum column width\AR\NC \type{k} \VL Insert a kern both left and right of the column\AR\NC \type{i} \VL Add a kern to the left of the column\AR\NC \type{j} \VL Add a kern to the right of the column\LRSR
\HL
\NC left text \VL right column text \NC \AR\NC new row \VL new row \NC \AR\NC left text \VL \ReFormat[l]{reformatted} \NC Numeric and Math Item Keys \SRAR
\HL
\NC \typeuse{n2} Spanning entry \VL Numeric item not in math mode\AR\NC \type{N} \VL Numeric item in math mode\AR\NC \type{m} \VL Each cell is in (inline) math mode. Equivalent to \type{b$ a$}\AR\NC \type{M} \VL Each cell is in display math mode. Equivalent to \type{\{b{$\displaystyle}a$}} \AR\NC \type{\m} \VL Equivalent to \type{l b{{}}m}\AR\NC \type{\M} \VL Equivalent to \type{l b{{}}M}\LRSR
\HL
\NC stoptable</context></td></tr></table>  ({{cmd|ReFormat}} can be abbreviated {{cmd|REF}} for brevity.) == Row Spans== It's also possible to create rowspans (i.e. cells that span more than one row) with the command {{cmd|Raise|(<i>dimen</i>){<i>content</i>}}} or {{cmd|Lower|(<i>dimen</i>){</i>content</i>}}} that raise or lower ''content'' by ''dimen''. <table cols="2"><tr valign="top"><td><texcode>\NC Style Keys \SRstarttable[|c|c|]
\HL
\NC \type{f\command} \VL Set font according to following \tex{command}\AR\NC Lower(.5\typelineheight){Ba} \VL Bold. Equivalent to b \type{f\bf}VL \AR\NC \type{I} \VL Italic. Equivalent to DC \type{fDL[1] \it}\ARDR\NC \type{S} VL \VL Slanted. Equivalent to \type{f\sl}\AR\NC \type{R} c \VL Roman. Equivalent to \type{f\rm}\AR\NC \type{T} \VL Teletype. Equivalent to \type{f\tt}\LR
\HL
\NC stoptable</texcode></td><td><context>\NC Tabskip Keys \SRstarttable[|c|c|]
\HL
\NC VL \typeLower(.5\lineheight){sa} \VL Set the tabskip to the right of this column and of all following columns up to the next b \type{s} or VL \AR\DC \type{o} keyDL[1] \ARDR\NC VL \type{o} VL c \VL Set the tabskip to the right of this column only\LRAR
\HL
\stoptable
</context>
</td><td>===Examples===; <code>|l|</code> : a left aligned column, as wide as necessary; <code>|lw(2cm)|</code> : a left aligned column of at least 2 cm width; <code>|p(2cm)|</code> : a centered(!) paragraph of 2 cm width; <code>|lp(.5\textwidth)|</code> : a left aligned paragraph of specified width; <code>...</code> : Please add more; <codetr>...</codetable> :
({{todocmd|add more examples Lower|(.5\lineheight){a}}} can be abbreviated {{cmd|LOW|{a}}} for brevity.) An alternative means of spanning rows by a tall object makes use of a bit of column definitionsTeX magic:{{cmd|smash|{tall object}}</tr></table>}:
<table cols="2"><tr valign=Column Spans=="top"><td>It's possible to create columnspans (i.e. cells that span more than one column) with the command <cmdtexcode>use\starttable[|M|c|]\HL\VL \VL a \VL \AR\DC \DL[1] \DR\VL \smash{\sum_0^N} \VL b \VL \AR\DC \DL[1] \DR\VL \VL c \VL \AR\HL\stoptable<i/texcode>N</itd><td>]</cmdcontext> where ''\starttable[|M|c|]\HL\VL \VL a \VL \AR\DC \DL[1] \DR\VL \smash{\sum_0^N'' is the number of columns spanned by the cell. It's often necessary to use } \VL b \VL \AR\DC \DL[1] \DR\VL \VL c \VL \AR\HL\stoptable<cmd/context>ReFormat[<i/td>new keys</itr>]</cmdtable> to reformat this specific cell according to the ''new keys''. {{todo|example for column spans}}
==Table as Floating Object==
<texcode>
\placetable[here][tab:sample]{sample table}{
\starttable ...
\stoptable
}
</texcode>
* See [[Floating Objects]] in general.
* If you need information about <{{cmd>|placetable</cmd> }} look after <{{cmd>|placefloat</cmd> }} in the manual or texshow!* If you'd like do not want a caption for your table, to get rid of it altogether you have to add "none" to settings and then leave out the braces empty; if you only leave the braces empty, your table's caption will still be numbered (here: "sample tableTable 1"etc.), you can't simply leave the braces empty but must write . <tttexcode>\placetable[here,none][tab:sample]{}{\starttable ...\stoptable}</tttexcode>!
==Background Colors==
Note: Adding color to tables using the `\CL` and `\BL` commands appears to be deprecated in MKIV; see: http://wiki.contextgarden.net/Tabulate A very nice application in table are background colors for rows/cells (a feature that doesn't work in [[tabulateTabulate]]):
<table cols="2"><tr valign="top"><td>
\HL
\BL[1]\SR
\NC Command \NC Meaning \NC\SR
\HL
\NC \tex{NC} \NC next column \NC\FR\NC \tex{NR} \NC next row \NC\LR
\HL
\CL[green]\SR
\NC \tex{AR} \NC automatic row \NC\SR
\HL
\stoptable
\HL
\BL[1]\SR
\NC Command \NC Meaning \NC\SR
\HL
\NC \tex{NC} \NC next column \NC\FR\NC \tex{NR} \NC next row \NC\LR
\HL
\CL[green]\SR
\NC \tex{AR} \NC automatic row \NC\SR
\HL
\stoptable
won't cover the whole cell.
* <{{cmd>|BL</cmd> }} makes a gray background: the optional argument tells BL how many cells it should color* <{{cmd>|CL</cmd> }} makes a colored linerow
==Fit Table Width==
<!-- It makes no sense to typeset this here. -->
Since table module has been under [http://www.ntg.nl/pipermail/ntg-context/2010/055004.html reconstruction] this approach works only for MKII. In MKIV one can use
 
<texcode>
\starttable[|l|l|][textwidth=max]
\HL
\VL foo foo foo foo foo foo \VL bar bar bar bar bar bar \VL\AR
\HL
\stoptable
</texcode>
 
to change the width of the current table only.
 
<code>\setuptables[textwidth=...]</code> will affect the behavior of every table.
 
== Booktabs ==
 
Latex has an excellent package called booktabs for typesetting tables. The main features of that package is that you can have top, mid, and bottom rules of different thickness. It is possible to achieve similar effects using tables. For example, to match the default settings of booktabs (Well almost, this gives a top and bottom rules of 0.09em while booktabs sets it to 0.08em).
 
<table cols="2"><tr valign="top"><td>
<texcode>
\setuptables[rulethickness=0.03em]
 
\starttable[s0|l|i2l|i2r|]
\HL[3]
\NC \Use2[c]{Item} \NC \NC \AR
\DL[2] \DC \DR
\NC Animal \NC Description \NC Price (\$) \NC \AR
\HL[2]
\NC Gnat \NC per gram \NC 13.65 \NC \AR
\NC \NC each \NC 0.01 \NC \AR
\NC Gnu \NC stuffed \NC 92.50 \NC \AR
\NC Emu \NC stuffed \NC 33.33 \NC \AR
\NC Armadillo \NC frozen \NC 8.99 \NC \AR
\HL[3]
\stoptable
</texcode>
</td><td>
<context>
\setuppapersize[A5]
\setuptables[rulethickness=0.03em]
 
\starttable[s0|l|i2l|i2r|]
\HL[3]
\NC \Use2[c]{Item} \NC \NC \AR
\DL[2] \DC \DR
\NC Animal \NC Description \NC Price (\$) \NC \AR
\HL[2]
\NC Gnat \NC per gram \NC 13.65 \NC \AR
\NC \NC each \NC 0.01 \NC \AR
\NC Gnu \NC stuffed \NC 92.50 \NC \AR
\NC Emu \NC stuffed \NC 33.33 \NC \AR
\NC Armadillo \NC frozen \NC 8.99 \NC \AR
\HL[3]
\stoptable
</context>
</td></tr></table>
[[Category:Tables]]
8

edits

Navigation menu