Changes

Jump to navigation Jump to search
967 bytes added ,  14:50, 19 January 2006
more/better structure; reworked keys table as ConTeXt table
< [[Tables Overview]]| [[tabulate]] | [[Tables]] >
This is ConTeXts oldest table module. It uses the same formatting as [[tabulate]]. (See see [[Tables Overview]] for an 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 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]].
 
== Basic Commands ==
 
<table cols="2"><tr valign="top"><td>
<texcode>
\placetable[here][tab:sample]{sample table}
\starttable[|l|l|]
\HL
\NC Command \NC VL Meaning \SR % or \NC\SRAR
\HL
\NC \tex{NC} \NC VL next column \NC\FRAR\NC \tex{HL} \NC VL horizontal line \NC\MRAR\NC \tex{VL} \NC VL vertical line \NC\MRAR\NC \tex{NR} \NC VL next row \NC\LR
\HL
\NC \tex{SR} \NC VL single row \NC\FRAR\NC \tex{FR} \NC VL first row \NC\MRAR\NC \tex{MR} \NC VL middle row \NC\MRAR\NC \tex{LR} \NC VL last row \LR % or \NC\LRAR
\HL
\NC \tex{AR} \NC VL automatic row \SR % or \NC\SRAR
\HL
\stoptable
</texcode>
</td><td>
<context>
\switchtobodyfont[ss, 8pt]
\starttable[|l|l|]
\HL
\NC Command \VL Meaning \SR % or \NC\AR
\HL
\NC \tex{NC} \VL next column \AR
\NC \tex{HL} \VL horizontal line \AR
\NC \tex{VL} \VL vertical line \AR
\NC \tex{NR} \VL next row \LR
\HL
\NC \tex{SR} \VL single row \AR
\NC \tex{FR} \VL first row \AR
\NC \tex{MR} \VL middle row \AR
\NC \tex{LR} \VL last row \LR % or \NC\AR
\HL
\NC \tex{AR} \VL automatic row \SR % or \NC\AR
\HL
\stoptable
</context>
</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.
If you need information about <cmd>placetable</cmd> look after <cmd>placefloat</cmd> in the manual!If you'd like to leave out the table's caption, you can't simply leave the braces empty but must write <tt>none</tt>! 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 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.==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 a necessary. The formatting keys for each column can be a choice of{|! Key || Meaning|-! colspan="2" | Primitive keys|-|a{<i>tokens</i>} || Adds <i>tokens</i> '''after''' the column content|-|b{<i>tokens</i>} || Adds <i>tokens</i> '''before''' the column content|-|\{ || Enclose the column in braces|-|*{<i>n</i>}{<i>keys</i>} || Equivalent to repeating the formatting keys <i>keys</i> <i>n</i> times|-! colspan="2" | Positioning keys|-|\LeftGlue || Specifies the left glue to be used before the column|-|\RightGlue || Specifies the right glue to be used after the column|-|l || Left-align the column|-|c || Center the column|-|r || Right-align the column|-|k || Insert a kern both left and right of the column|-|i || Add a kern to the left of the column|-|j || Add a kern to the right of the column|-! colspan="2" | Numeric item keys|-|n || Numeric item not in math mode|-|N || Numeric item in math mode|-! colspan="2" | Attribute keys|-|m || Each cell is in (inline) math mode. Equivalent to <tt>b$ a$</tt>|-|M || Each cell is in display math mode. Equivalent to <tt>\{b{$\displaystyle}a$</tt>|-|\m || Equivalent to <tt>l b{{}}m</tt>|-|\M || Equivalent to <tt>l b{{}}M</tt>|-|f || Set font according to following <cmd>command</cmd>|-|B || Bold. Equivalent to <tt>f\bf</tt>|-|I || Italic. Equivalent to <tt>f\it</tt>|-|S || Slanted. Equivalent to <tt>f\sl</tt>|-|R || Roman. Equivalent to <tt>f\rm</tt>|-|T || Teletype. Equivalent to <tt>f\tt</tt>|-|p || Set each cell as a paragraph|-! colspan="2" | Minimum column width key|-|w || Set minimum column width|-! colspan="2" | Tabskip keys|-|s || Set the tabskip to the right of this column and of all following columns until the next <tt>s</tt> or <tt>o</tt> key|-|o || Set the tabskip to the right of this column only.|}  It's possible to create columnspans (i.e. cells that span more than one column) with the command <cmd>use[<i>N</i>]</cmd> where <i>N</i> is the number of columns spanned by the cell. It's often necessary to use <cmd>ReFormat[<i>new keys</i>]</cmd> to reformat this specific cell according to the <i>new keys</i>. The only ConTeXt docs about it are in [http://www.pragma-ade.com/general/manuals/ms-cb-en.pdf ms-cb-en.pdf]. The sample looks like this:
<context>
\placetableswitchtobodyfont[here][tab:sample8pt]\HL\NC \bf Key \VL \bf Meaning \SR\HL\NC \NC Primitive Keys \SR\HL\NC \type{a{tokens}}\VL Adds \type{tokens} {\em after} the column content\AR\NC \type{b{tokens}}\VL Adds \type{tokens} '''before''' the column content\AR\NC {\tt \backslash\{ } \VL Enclose the column in braces \AR\NC \type{*{n}{keys}}\VL Equivalent to repeating the formatting keys \type{keys} \type{n} times\NC\LR\HL\NC \NC Positioning Keys\SR\HL\NC \type{\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{l} \VL left-aligned column\AR\NC \type{c} \VL centered column\AR\NC \type{r} \VL right-aligned column\AR\NC \type{p} \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\LR\HL\NC \NC Numeric and Math Item Keys \SR\HL\NC \type{n} \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{sample table$\displaystyle}a$}} \AR\starttable[|NC \type{\m} \VL Equivalent to \type{l|b{{}}m}\AR\NC \type{\M} \VL Equivalent to \type{l|]b{{}}M}\LR
\HL
\NC Command \NC Meaning \NCStyle Keys \SR
\HL
\NC \type{f\command} \VL Set font according to following \tex{command}\AR\NC \type{B} \NC next column VL Bold. Equivalent to \type{f\NCbf}\FRAR\NC \textype{HLI} \NC horizontal line VL Italic. Equivalent to \type{f\NCit}\MRAR\NC \textype{S} \VLSlanted. Equivalent to \type{f\sl} \AR\NC vertical line \type{R} \VL Roman. Equivalent to \type{f\NCrm}\MRAR\NC \textype{NRT} \NC next row VL Teletype. Equivalent to \type{f\NCtt}\LR
\HL
\NC \tex{SR} \NC single row Tabskip Keys \NC\FR\NC \tex{FR} \NC first row \NC\MR\NC \tex{MR} \NC middle row \NC\MR\NC \tex{LR} \NC last row \NC\LRSR
\HL
\NC \textype{s} \VL Set the tabskip to the right of this column and of all following columns up to the next \type{s} or \type{o} key\AR} \NC automatic row \NCtype{o} \VL Set the tabskip to the right of this column only\SRLR
\HL
\stoptable
</context>
==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>]</cmd> where ''N'' is the number of columns spanned by the cell. It's often necessary to use <cmd>ReFormat[<i>new keys</i>]</cmd> to reformat this specific cell according to the ''new keys''. ==Table as Floating Object== <texcode>\placetable[here][tab:sample]{sample table}\starttable ...</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 to leave out the table's caption (here: "sample table"), you can't simply leave the braces empty but must write <tt>none</tt>! ==Background Colors== A very nice application in table are background colors for rows/cells (a feature that doesn't work in [[tabulate]]):
<texcode>
\setupcolors[state=start]
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 line
<context>
\setupcolors[state=start]
</context>
=Examples=Fit Table Width==
Hans posted a solution to the list for fitting a wide table (with paragraphs and vertical lines) to the page width. The key to his solution is the (<code>.45\textwidth) </code> settings when setting each cell as a paragraph.
<texcode>
\SetTableToWidth{\textwidth}
gardener
1,125

edits

Navigation menu