https://wiki.contextgarden.net/api.php?action=feedcontributions&user=Bjarchi&feedformat=atomWiki - User contributions [en]2024-03-29T13:10:47ZUser contributionsMediaWiki 1.34.1https://wiki.contextgarden.net/index.php?title=Tabulate&diff=21446Tabulate2013-03-20T16:41:51Z<p>Bjarchi: Added CT variant of coloring, for text color</p>
<hr />
<div>< [[Tables Overview]] | [[Table]] ><br />
<br />
<br />
=Summary=<br />
<br />
{{cmd|starttabulate}} is a versatile table environment.<br />
It supports ''paragraphs'' in cells, ''vertical rules'' (for<br />
those typographically less demanding jobs&nbsp;…), and<br />
''colorization'' of those rules, the background of fields as well<br />
as the text itself.<br />
<br />
'''Warning''': When you want to use tables with macros use \starttable and \stoptable. \starttabulate and \stoptabulate does not work correctly with macros.<br />
<br />
=Basic commands=<br />
<br />
The control sequence <tt>\starttabulate[#1]</tt> takes a layout<br />
string as optional argument.<br />
As is common with tables in TeX-based typesetting, this string<br />
(in its basic variant) consists primarily of the ''bar''<br />
character (“<tt>|</tt>”) as delimiter for columns,<br />
and of the letters <tt>c</tt>, <tt>l</tt>, as well as <tt>r</tt>,<br />
denoting the ''alignment'' within cells of this row.<br />
<br />
For instance consider a two-column table: if any text in the<br />
first column should be right aligned (''real''<br />
[[right and left|<tt>flushright</tt>]]) and the second column<br />
left aligned, the corresponding format string would be<br />
<tt>|l|r|</tt>.<br />
''NB'': those bars, as stated above, denote cell limits only<br />
&ndash; ''not'' vertical lines.<br />
<br />
<!--<br />
- wtf this listing was full of <tab> chars‽ Was this supposed<br />
- to be a bad pun on *tabulate*?<br />
--><br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\starttabulate[|r|l|]<br />
\HL<br />
\NC {\bf format} \NC {\bf meaning} \NC\NR<br />
\HL<br />
\NC c \NC centered \NC\NR<br />
\NC l \NC left aligned \NC\NR<br />
\NC r \NC right aligned \NC\NR<br />
\NC w(1cm) \NC one line, fixed width \NC\NR<br />
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR<br />
\NC cg(.) \NC align on a character \NC\NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
|<br />
|<context><br />
\setuppapersize[A5]<br />
\starttabulate[|r|l|]<br />
\HL<br />
\NC {\bf format} \NC {\bf meaning} \NC\NR<br />
\HL<br />
\NC c \NC centered \NC\NR<br />
\NC l \NC left aligned \NC\NR<br />
\NC r \NC right aligned \NC\NR<br />
\NC w(1cm) \NC one line, fixed width \NC\NR<br />
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR<br />
\NC cg(.) \NC align on a character \NC\NR<br />
\HL<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
* <tt>HL</tt> draws a horizontal rule,<br />
* <tt>NC</tt> marks a new column (or new cell),<br />
* <tt>NR</tt> starts a new row.<br />
* <tt>NB</tt> starts a new row as a block (avoids page breaking inside of a block, to keep some lines together; available since beta of 2011-12-21)<br />
<br />
<br />
When using fixed width, you can use values relative to the<br />
current page-width. For example: if you want the previous table<br />
take up all the width and having the second column taking three<br />
quarters of the space, change the starttabulate to:<br />
<texcode><br />
\starttabulate[|rw(.25\textwidth)|lw(.75\textwidth)|]<br />
</texcode><br />
<br />
=Spanning Multiple Pages=<br />
<br />
Tabulate may extend to adjacient pages if needed.<br />
To achieve this the argument <tt>split</tt> must be set to<br />
''true''.<br />
''NB'': the difference between setting and unsetting this<br />
argument may not be visible on the first few pages. Rather, it<br />
seems to affect the ''end'' of the environment.<br />
<br />
<context source=yes><br />
\setuppapersize[A10, landscape][A8, landscape]<br />
\setuppaper[nx=2,ny=2]<br />
\setuparranging[XY]<br />
<br />
\switchtobodyfont[5pt]<br />
\setuppagenumbering[location={header,inright}]<br />
\showframe[edge]<br />
<br />
\setuptabulate<br />
[split=yes,<br />
header=text,<br />
title={\color[red] Fenchurch St. Paul},<br />
frame=on]<br />
<br />
\starttabulate[|p(1.2cm)|p(1.2cm)|]<br />
\dorecurse{6}{<br />
\NC Bells: \NC Tin tan din dan bim bam bom bo \NC\NR<br />
\HL<br />
\NC Name: \NC Tailor Paul \NC \NR <br />
\HL<br />
}<br />
\stoptabulate<br />
</context><br />
<br />
<br />
==Titles==<br />
<br />
A tabulating environment can have an optional name which will be<br />
repeated above at every page break that occurs inside the table.<br />
This name needs to be specified as the argument of the<br />
<tt>title</tt> key of <tt>\setuptabulate</tt>.<br />
The <tt>header</tt> key has to be set to <em>text</em> for this<br />
to work.<br />
<br />
<context source=yes><br />
\setuppapersize[A10, landscape][A8, landscape]<br />
\setuppaper[nx=2,ny=2]<br />
\setuparranging[XY]<br />
<br />
\switchtobodyfont[5pt]<br />
\setuppagenumbering[location={header,inright}]<br />
\showframe[edge]<br />
<br />
\setuptabulate<br />
[split=yes,<br />
header=text,<br />
title={\color[red] Fenchurch St. Paul},<br />
frame=on]<br />
<br />
\starttabulate[|p(1.2cm)|p(1.2cm)|]<br />
\dorecurse{6}{<br />
\NC Bells: \NC Tin tan din dan bim bam bom bo \NC\NR<br />
\HL<br />
\NC Name: \NC Tailor Paul \NC \NR <br />
\HL<br />
}<br />
\stoptabulate<br />
</context><br />
<br />
<!--<br />
- ==Headers and Footers==<br />
- As I couldn’t get footers running I just comment this and<br />
- leave it to whoever discovers the trick to activate them.<br />
- (The <tt>footer=</tt> key seems to be implemented for<br />
- “\setuptabulate” but I couldn’t notice any effect.<br />
--><br />
<br />
==Headers==<br />
Tabulate supports header rows that can be repeated over new table<br />
pages instead of the title.<br />
There is a separate environment <tt>\starttablehead</tt> where<br />
this header row has to be specified in advance of its use in a<br />
tabulation.<br />
<br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\setuptabulate[split=yes,header=repeat]<br />
<br />
\starttabulatehead<br />
\HL<br />
\NC {\bf format char} \NC {\bf meaning} \NC \AR<br />
\HL<br />
\stoptabulatehead<br />
<br />
\starttabulate[|r|l|]<br />
\NC c \NC centered \NC \AR<br />
\NC l \NC left aligned \NC \AR<br />
\NC r \NC right aligned \NC \AR<br />
\stoptabulate<br />
</texcode><br />
|<br />
| <context><br />
\setuppapersize[A5]<br />
<br />
\setuptabulate[split=yes,header=repeat]<br />
<br />
\starttabulatehead<br />
\HL<br />
\NC {\bf format char} \NC {\bf meaning} \AR<br />
\HL<br />
\stoptabulatehead<br />
<br />
\starttabulate[|r|l|]<br />
\NC c \NC centered \AR<br />
\NC l \NC left aligned \AR<br />
\NC r \NC right aligned \AR<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
=Individualizing the Tabulate Look=<br />
<br />
Hans initially announced support for vertical lines and colors on<br />
the mailing list.[http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html]<br />
<br />
==Rules==<br />
<br />
===Horizontal Rules===<br />
<br />
As already demonstrated above, the <tt>\HL</tt> statement inserts<br />
a hairline after the current line.<br />
This particularly useful when demarking header and footer rows or<br />
separated parts of a table that should not be as closely<br />
associated as the rows between the rules.<br />
<br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\stoptabulate<br />
</texcode><br />
| <context><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
Context supports different categories of rules that can be<br />
configured individually in order to discern various applications.<br />
Their behaviour accounts for the designated use, e.&nbsp;g.<br />
<tt>\ML</tt> (mid rules) are intended to be deployed between<br />
ordinary rows of the table body and will prevent page breaks<br />
&ndash; no way you’d end up with a rogue hairline desecrating<br />
the bottom of your page’s text area.<br />
{|cellpadding="10" style="border:2px solid #addeff"<br />
! style="background:#addeff;" | Type !! Description<br />
|-<br />
|<tt>\HL</tt> || standard horizontal rule;<br />
|-<br />
|<tt>\FL</tt> || first rule;<br />
|-<br />
|<tt>\ML</tt> || mid rule;<br />
|-<br />
|<tt>\LL</tt> || bottom rule;<br />
|-<br />
|<tt>\LL</tt> and <tt>\TL</tt> || bottom rule;<br />
|-<br />
|<tt>\BL</tt> || last rule.<br />
|}<br />
<br />
Additionally, there is an options <tt>rulecolor</tt> for<br />
<tt>\setuptabulate</tt> that allows for those rules to be tinted.<br />
<br />
<texcode><br />
\setuptabulate[rulecolor=red]<br />
<br />
\starttabulate[|r|c|l|] <br />
\FL<br />
\NC first row \NC test \NC test \NC\NR <br />
\ML<br />
\NC rows in \NC test \NC test \NC\NR <br />
\NC between \NC test \NC test \NC\NR <br />
\LL <br />
\NC last row \NC test \NC test \NC\NR <br />
\BL<br />
\stoptabulate<br />
</texcode><br />
<br />
Other types can be discovered in the source<br />
([[source:tabl-tbl.mkiv|tabl-tbl.mkiv]]).<br />
<br />
===Vertical Rules===<br />
<br />
The <tt>\VL</tt> command serves as a replacement for <tt>\NC</tt><br />
to mark a cell border wherever a vertical rule may be desired (if<br />
they are to be desired at all from a typographical point of<br />
view).<br />
<br />
<texcode><br />
\starttabulate[||||] <br />
\NC test \VL test \VL test \VL\NR <br />
\VL test \NC test \VL test \VL\NR <br />
\VL test \VL test \NC test \VL\NR <br />
\VL test \VL test \VL test \NC\NR <br />
\stoptabulate<br />
</texcode><br />
<br />
==Coloring==<br />
<br />
The following elements can be colorized: rules, cell backgrounds,<br />
and, obviously, common text.<br />
<br />
===Colorizing Rules===<br />
<br />
For ''horizontal rules'' see above.<br />
<br />
For ''vertical rules'', <tt>\VL</tt> takes a defined color as an<br />
optional argument.<br />
<br />
<texcode><br />
\starttabulate[|r|c|l|] <br />
\VL test \VL[red] red rule \VL test \VL \NR <br />
\VL test \VL[green] green rule \VL test \VL \NR <br />
\VL test \VL[blue] blue rule \VL test \VL \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
===Colorizing Backgrounds & Text===<br />
Backgrounds and text can be colorized either on column basis or<br />
individually by cell.<br />
<br />
There are five color-specific control sequences:<br />
{|<br />
|<tt>CR</tt> || color is applied to the background of the text and the remaining space on the right.<br />
|-<br />
|<tt>CC</tt> || color is applied to the background of the text only.<br />
|-<br />
|<tt>CM</tt> || color is applied to the background of the text and the remaining space on both sides.<br />
|-<br />
|<tt>CL</tt> || color is applied to the background of the text and the remaining space on the left.<br />
|-<br />
|<tt>CT</tt> || color is applied to the text itself - in other words, the "foreground color."<br />
|}<br />
These are to complement the normal table layout expression (the<br />
first argument to <tt>\starttabulate</tt>.<br />
Thus, in order to colorize a four column table with the initial<br />
layout <tt>|c|c|c|c|</tt> it will have to be modified as follows:<br />
<texcode><br />
\starttabulate[|CR{red}c|CC{yellow}c|CM{green}c|CL{blue}c|] <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
Those control sequences, if applied within the table body, can<br />
replace the ordinary <tt>\NC</tt>, allowing individual cells to<br />
be colorized.<br />
<texcode><br />
\starttabulate[|c|c|c|c|c|c|]<br />
\NC g \NC l \NC i \NC d \NC e \NC r \NC \NR <br />
\NC g \NC l \NC i \CM[blue] d \NC e \NC r \NC \NR <br />
\NC g \NC l \NC i \NC d \CM[blue] e \NC r \NC \NR <br />
\NC g \NC l \CM[blue] i \CM[blue] d \CM[blue] e \NC r \NC \NR <br />
\NC g \NC l \NC i \NC d \NC e \NC r \NC \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
'''caveat emptor'''! The background coloring does apply only to<br />
the ''first'' row of a paragraph cell. Any other cell will come<br />
out colorless. If you need to color an entire multi-line cell,<br />
you will need to switch to another<br />
[[Tables Overview|tabulation variant]].<br />
<br />
===Colorizing Cell Text===<br />
''Normal text'' inside cells gets its color via the<br />
[[Color|standard coloring commands]], or by the <br />
shorter variant described above.<br />
<br />
<texcode><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC {\colored[red] test} \NC test \NC\NR <br />
\NC test \NC {\colored[green] test} \NC test \NC\NR <br />
\NC test \NC {\colored[blue] test} \NC test \NC\NR <br />
\NC test \NC {\colored[cyan] test} \NC test \NC\NR <br />
\stoptabulate<br />
</texcode><br />
<br />
== Vertical Distance Between Rows ==<br />
<br />
There does not seem to be an official interface for<br />
vertical skips.<br />
Manually placed <code>\blank</code>s are<br />
<code>\unskipped</code> on purpose.<br />
However, as expected there is a token list<br />
<code>\t_tabl_tabulate_every_after_row</code> that is<br />
placed after a line is finished.<br />
So, in order to get a vertical spacing of half a baseline<br />
distance you can use this code:<br />
<br />
<texcode><br />
\unprotect<br />
\appendtoks<br />
\blank[halfline]<br />
\to \t_tabl_tabulate_every_after_row<br />
\protect<br />
<br />
</texcode><br />
<br />
=Using math mode=<br />
<br />
If you want to display numerics, you can simply use <cmd>NN</cmd> for a new column instead of <cmd>NC</cmd>. This command works similar to the [http://www.pragma-ade.com/general/magazines/mag-0003.pdf digit-module]. Therefore you can also abbreviate:<br />
<br />
<texcode>\starttabulate[|l|l|]<br />
\HL<br />
\NN 10e-3 \NN 10e+3 \NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
<br />
instead of<br />
<br />
<texcode><br />
\starttabulate[|l|l|]<br />
\HL<br />
\NC $10\cdot 10^{-3}$ \NC $10 \cdot 10^3$ \NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
<br />
although both variants do work.<br />
<br />
<br />
=Itemization inside a tabulation=<br />
<br />
<!--(added by Willi Egger 04-08-2011)--><br />
<br />
The following issue is related to MKIV:<br />
<br />
When using an itemization inside a tabulation where one uses also the <br />
<tt>\head</tt> command there occurs a snapping problem. This is related to penalties which force a twoline split whereas the snapping mechanism prevents this. As a result two lines are typeset on top of each other. The solution is to add the following statement to the preamble:<br />
<texcode>\tabulatesplitlinemode \plustwo</texcode><br />
<br />
The following code provided by Wolfgang Schuster demonstrates the problem: Compile with and without the line <tt>\tabulatesplitlinemode\plustwo</tt><br />
<br />
<texcode><br />
\tabulatesplitlinemode \plustwo<br />
\starttabulate[|p|]<br />
\NC<br />
one \par<br />
\blank[penalty:10000]<br />
two \par<br />
\blank[penalty:10000]<br />
three<br />
\NC\NR<br />
\stoptabulate<br />
</texcode><br />
<br />
<br />
=See also=<br />
<br />
* More features are constantly added and documented in the {{src|tabl-tbl.mkiv|source}}.<br />
* {{cmd|starttabulate}}<br />
* [[TABLE|Natural Tables]]<br />
* {{cmd|starttable}}<br />
<br />
[[Category:Tables]]</div>Bjarchi