Difference between revisions of "Tabulate"

From Wiki
Jump to navigation Jump to search
(→‎Basic commands: You cannot leave out \NC before \NR (at least in MkIV))
(general overaul)
Line 1: Line 1:
 
< [[Tables Overview]] | [[Table]] >
 
< [[Tables Overview]] | [[Table]] >
  
== Basic commands ==
 
  
Rather simple tabulating. You ''need'' the bars in the formatting field of <cmd>starttabulate</cmd>! '''If you want vertical lines, you need another table mode''' (see [[Tables]]).
+
=Summary=
  
This is especially suited if you want to have paragraphs in one (or more) of the tabulate columns.
+
[[cmd:starttabulate|Tabulate]] is a versatile table environment.
 +
It supports ''paragraphs'' in cells, ''vertical rules'' (for
 +
those typographically less demanding jobs&nbsp;…), and
 +
''colorization'' of those rules, the background of fields as well
 +
as the text itself.
  
The sample describes the formatting characters:
+
=Basic commands=
 +
 
 +
The control sequence <tt>\starttabulate[#1]</tt> takes a layout
 +
string as optional argument.
 +
As is common with tables in TeX-based typesetting, this string
 +
(in its basic variant) consists primarily of the ''bar''
 +
character (“<tt>|</tt>”) as delimiter for columns,
 +
and of the letters <tt>c</tt>, <tt>l</tt>, as well as <tt>r</tt>,
 +
denoting the ''alignment'' within cells of this row.
 +
 
 +
For instance consider a two-column table: if any text in the
 +
first column should be right aligned (''real''
 +
[[right and left|<tt>flushright</tt>]]) and the second column
 +
left aligned, the corresponding format string would be
 +
<tt>|l|r|</tt>.
 +
''NB'': those bars, as stated above, denote cell limits only
 +
&ndash; ''not'' vertical lines.
 +
 
 +
<!--
 +
-  wtf this listing was full of <tab> chars‽ Was this supposed
 +
-  to be a bad pun on *tabulate*?
 +
-->
 
{|
 
{|
 
  ! width="55%"|
 
  ! width="55%"|
Line 14: Line 38:
 
  |-
 
  |-
 
  | <texcode>
 
  | <texcode>
\starttabulate[|l|l|]
+
\starttabulate[|r|l|]
 
\HL
 
\HL
\NC format \NC meaning \NC\NR
+
\NC {\bf format} \NC {\bf meaning}                    \NC\NR
 
\HL
 
\HL
\NC c \NC centered \NC\NR
+
\NC c     \NC centered                               \NC\NR
\NC l \NC left aligned \NC\NR
+
\NC l     \NC left aligned                           \NC\NR
\NC r \NC right aligned \NC\NR
+
\NC r     \NC right aligned                         \NC\NR
\NC w(1cm) \NC one line, fixed width \NC\NR
+
\NC w(1cm) \NC one line, fixed width                 \NC\NR
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR
+
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR
\NC cg(.) \NC align on a character       \NC\NR
+
\NC cg(.) \NC align on a character                   \NC\NR
 
\HL
 
\HL
 
\stoptabulate
 
\stoptabulate
Line 29: Line 53:
 
|
 
|
 
|<context>
 
|<context>
\starttabulate[|l|l|]
+
\starttabulate[|r|l|]
 
\HL
 
\HL
\NC format \NC meaning \NC\NR
+
\NC {\bf format} \NC {\bf meaning}                    \NC\NR
 
\HL
 
\HL
\NC c \NC centered \NC\NR
+
\NC c     \NC centered                               \NC\NR
\NC l \NC left aligned \NC\NR
+
\NC l     \NC left aligned                           \NC\NR
\NC r \NC right aligned \NC\NR
+
\NC r     \NC right aligned                         \NC\NR
\NC w(1cm) \NC one line, fixed width \NC\NR
+
\NC w(1cm) \NC one line, fixed width                 \NC\NR
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR
+
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR
 +
\NC cg(.)  \NC align on a character                  \NC\NR
 
\HL
 
\HL
 
\stoptabulate
 
\stoptabulate
Line 43: Line 68:
 
|}
 
|}
  
* HL is horizontal line
+
* <tt>HL</tt> draws a horizontal rule,
* NC is new column (or new cell)
+
* <tt>NC</tt> marks a new column (or new cell),
* NR is new row
+
* <tt>NR</tt> starts new row.
 +
 
 +
It is generally not necessary to conclude lines with
 +
<tt>\NC\NR</tt> as <tt>\AR</tt> (for <em>a</em>uto<em>r</em>ow)
 +
will do the job as well.
 +
 
 +
=Spanning Multiple Pages=
 +
 
 +
Tabulate may extend to adjacient pages if needed.
 +
To achieve this the argument <tt>split</tt> must be set to
 +
''true''.
 +
''NB'': the difference between setting and unsetting this
 +
argument may not be visible on the first few pages. Rather, it
 +
seems to affect the ''end'' of the environment.
 +
 
 +
<context source="yes">
 +
\setuppapersize [XY][A4]
 +
\setuppaper    [nx=2,ny=2]
 +
\setuparranging [XY]
 +
\setupbodyfont[10pt]
 +
 
 +
\starttext
 +
 
 +
\setuptabulate[split=yes]
 +
 
 +
\starttabulate
 +
\dorecurse{2}{
 +
  \NC test \NC \input tufte  \relax \NC \NR
 +
  \NC test \NC \input dawkins \relax \NC \NR
 +
}
 +
\stoptabulate
 +
 
 +
\stoptext \endinput
 +
</context>
 +
 
 +
==Titles==
 +
 
 +
A tabulating environment can have an optional name which will be
 +
repeated above at every page break that occurs inside the table.
 +
This name needs to be specified as the argument of the
 +
<tt>title</tt> key of <tt>\setuptabulate</tt>.
 +
The <tt>header</tt> key has to be set to <em>text</em> for this
 +
to work.
 +
 
 +
<texcode>
 +
\setuptabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}]
 +
 
 +
\starttabulate
 +
\dorecurse{2}{
 +
  \NC Ed Tufte    \NC \input tufte  \relax \NC \NR
 +
  \NC Dick Dawkins \NC \input dawkins \relax \NC \NR
 +
}
 +
</texcode>
 +
 
 +
<context>
 +
\setuppapersize [XY][A4]
 +
\setuppaper    [nx=2,ny=2]
 +
\setuparranging [XY]
 +
 
 +
\starttext
 +
 
 +
\setuptabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}]
 +
 
 +
\starttabulate
 +
\dorecurse{2}{
 +
  \NC Ed Tufte    \NC \input tufte  \relax \NC \NR                                             
 +
  \NC Dick Dawkins \NC \input dawkins \relax \NC \NR
 +
}
 +
\stoptabulate
  
== Headers and Footers ==
+
\stoptext \endinput
 +
</context>
  
In long tabulations you'd like to get your headers (and perhaps footers) repeated on every page:
+
<!--
 +
-  ==Headers and Footers==
 +
-  As I couldn’t get footers running I just comment this and
 +
-  leave it to whoever discovers the trick to activate them.
 +
(The <tt>footer=</tt> key seems to be implemented for
 +
-  “\setuptabulate” but I couldn’t notice any effect.
 +
-->
 +
==Headers==
 +
Tabulate supports header rows that can be repeated over new table
 +
pages instead of the title.
 +
There is a separate environment <tt>\starttablehead</tt> where
 +
this header row has to be specified in advance of its use in a
 +
tabulation.
  
 
{|
 
{|
Line 57: Line 163:
 
  |-
 
  |-
 
  | <texcode>
 
  | <texcode>
\setuptabulate[headers=repeat] % same for footers
+
\setuptabulate[split=yes,header=repeat]
 +
 
 
\starttabulatehead
 
\starttabulatehead
\HL
+
  \HL
\NC format \NC meaning \NC\NR
+
  \NC {\bf format char} \NC {\bf meaning} \AR
\HL
+
  \HL
 
\stoptabulatehead
 
\stoptabulatehead
\starttabulate[|l|l|]
+
 
\NC c \NC centered \NC\NR
+
\starttabulate[|r|l|]
\NC l \NC left aligned \NC\NR
+
    \NC c \NC centered     \AR
\NC r \NC right aligned \NC\NR
+
    \NC l \NC left aligned \AR
 +
    \NC r \NC right aligned \AR
 
\stoptabulate
 
\stoptabulate
 
</texcode>
 
</texcode>
 
|
 
|
 
| <context>
 
| <context>
\setuptabulate[headers=repeat] % same for footers
+
\setuptabulate[split=yes,header=repeat]
 +
 
 
\starttabulatehead
 
\starttabulatehead
 +
  \HL
 +
  \NC {\bf format char} \NC {\bf meaning} \AR
 +
  \HL
 +
\stoptabulatehead
 +
 +
\starttabulate[|r|l|]
 +
    \NC c      \NC centered        \AR
 +
    \NC l      \NC left aligned    \AR
 +
    \NC r      \NC right aligned  \AR
 +
\stoptabulate
 +
</context>
 +
|}
 +
 +
=Individualizing the Tabulate Look=
 +
 +
Hans initially announced support for vertical lines and colors on
 +
the mailing list.[http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html]
 +
 +
==Rules==
 +
 +
===Horizontal Rules===
 +
 +
As already demonstrated above, the <tt>\HL</tt> statement inserts
 +
a hairline after the current line.
 +
This particularly useful when demarking header and footer rows or
 +
separated parts of a table that should not be as closely
 +
associated as the rows between the rules.
 +
 +
{|
 +
! width="55%"|
 +
! width="10%"|
 +
! width="35%"|
 +
|-
 +
| <texcode>
 +
\starttabulate[|r|c|l|]
 +
\NC test \NC test \NC test \NC\NR
 +
\HL
 +
\NC test \NC test \NC test \NC\NR
 +
\NC test \NC test \NC test \NC\NR
 +
\HL
 +
\NC test \NC test \NC test \NC\NR
 +
\HL
 +
\stoptabulate
 +
</texcode>
 +
| <context>
 +
\starttabulate[|r|c|l|]
 +
\NC test \NC test \NC test \NC\NR
 +
\HL
 +
\NC test \NC test \NC test \NC\NR
 +
\NC test \NC test \NC test \NC\NR
 
\HL
 
\HL
\NC format \NC meaning \NC\NR
+
\NC test \NC test \NC test \NC\NR  
 
\HL
 
\HL
\stoptabulatehead
 
\starttabulate[|l|l|]
 
\NC c \NC centered \NC\NR
 
\NC l \NC left aligned \NC\NR
 
\NC r \NC right aligned \NC\NR
 
 
\stoptabulate
 
\stoptabulate
 
</context>
 
</context>
 
|}
 
|}
  
== Column Spans ==
+
Context supports different categories of rules that can be
 +
configured individually in order to discern various applications.
 +
Their behaviour accounts for the designated use, e.&nbsp;g.
 +
<tt>\ML</tt> (mid rules) are intended to be deployed between
 +
ordinary rows of the table body and will prevent page breaks
 +
&ndash; no way you’d end up with a rogue hairline desecrating
 +
the bottom of your page’s text area.
 +
{|cellpadding="10" style="border:2px solid #addeff"
 +
! style="background:#addeff;" | Type !! Description
 +
|-
 +
|<tt>\HL</tt> || standard horizontal rule;
 +
|-
 +
|<tt>\FL</tt> || first rule;
 +
|-
 +
|<tt>\ML</tt> || mid rule;
 +
|-
 +
|<tt>\LL</tt> || bottom rule;
 +
|-
 +
|<tt>\LL</tt> and <tt>\TL</tt> || bottom rule;
 +
|-
 +
|<tt>\BL</tt> || last rule.
 +
|}
 +
 
 +
Additionally, there is an options <tt>rulecolor</tt> for
 +
<tt>\setuptabulate</tt> that allows for those rules to be tinted.
 +
 
 +
<texcode>
 +
\setuptabulate[rulecolor=red]
 +
 
 +
\starttabulate[|r|c|l|]
 +
    \FL
 +
    \NC first row \NC test \NC test \NC\NR
 +
    \ML
 +
    \NC rows in  \NC test \NC test \NC\NR
 +
    \NC between  \NC test \NC test \NC\NR
 +
    \LL         
 +
    \NC last row  \NC test \NC test \NC\NR
 +
    \BL
 +
\stoptabulate
 +
</texcode>
 +
 
 +
Other types can be discovered in the source
 +
([[source:tabl-tbl.mkiv|tabl-tbl.mkiv]]).
 +
 
 +
===Vertical Rules===
 +
 
 +
The <tt>\VL</tt> command serves as a replacement for <tt>\NC</tt>
 +
to mark a cell border wherever a vertical rule may be desired (if
 +
they are to be desired at all from a typographical point of
 +
view).
 +
 
 +
<texcode>
 +
\starttabulate[||||]
 +
    \NC test \VL test \VL test \VL\NR
 +
    \VL test \NC test \VL test \VL\NR
 +
    \VL test \VL test \NC test \VL\NR
 +
    \VL test \VL test \VL test \NC\NR
 +
\stoptabulate
 +
</texcode>
 +
 
 +
==Coloring==
 +
 
 +
The following elements can be colorized: rules, cell backgrounds,
 +
and, obviously, common text.
 +
 
 +
===Colorizing Rules===
 +
 
 +
For ''horizontal rules'' see above.
 +
 
 +
For ''vertical rules'', <tt>\VL</tt> takes a defined color as an
 +
optional argument.
 +
 
 +
<texcode>
 +
\starttabulate[|r|c|l|]
 +
  \VL test \VL[red]    red rule    \VL test \VL \NR
 +
  \VL test \VL[green]  green rule  \VL test \VL \NR
 +
  \VL test \VL[blue]  blue rule  \VL test \VL \NR
 +
\stoptabulate
 +
</texcode>
 +
 
 +
===Colorizing Backgrounds===
 +
''Backgrounds'' can be colorized either on column basis or
 +
individually by cell.
 +
 
 +
There are four color-specific control sequences:
 +
{|
 +
|<tt>CR</tt> || color is applied to the background of the text and the remaining space on the right;
 +
|-
 +
|<tt>CC</tt> || color is applied to the background of the text only;
 +
|-
 +
|<tt>CM</tt> || color is applied to the background of the text and the remaining space on both sides;
 +
|-
 +
|<tt>CL</tt> || color is applied to the background of the text and the remaining space on the left.
 +
|}
 +
These are to complement the normal table layout expression (the
 +
first argument to <tt>\starttabulate</tt>.
 +
Thus, in order to colorize a four column table with the initial
 +
layout <tt>|c|c|c|c|</tt> it will have to be modified as follows:
 +
<texcode>
 +
\starttabulate[|CR{red}c|CC{yellow}c|CM{green}c|CL{blue}c|]
 +
    \NC test \NC test \NC test \NC test \NC \NR
 +
    \NC test \NC test \NC test \NC test \NC \NR
 +
    \NC test \NC test \NC test \NC test \NC \NR
 +
    \NC test \NC test \NC test \NC test \NC \NR
 +
\stoptabulate
 +
</texcode>
 +
 
 +
Those control sequences, if applied within the table body, can
 +
replace the ordinary <tt>\NC</tt>, allowing individual cells to
 +
be colorized.
 +
<texcode>
 +
\starttabulate[|c|c|c|c|c|c|]
 +
  \NC g \NC l \NC i \NC d \NC e \NC r \NC \NR
 +
  \NC g \NC l \NC i \CM[blue] d \NC e \NC r \NC \NR
 +
  \NC g \NC l \NC i \NC d \CM[blue] e \NC r \NC \NR
 +
  \NC g \NC l \CM[blue] i \CM[blue] d \CM[blue] e \NC r \NC \NR
 +
  \NC g \NC l \NC i \NC d \NC e \NC r \NC \NR
 +
\stoptabulate
 +
</texcode>
 +
 
 +
 
 +
===Colorizing Cell Text===
 +
''Normal text'' inside cells gets its color via the
 +
[[colors|standard coloring commands]].
 +
 
 +
<texcode>
 +
\starttabulate[|r|c|l|]
 +
  \NC test \NC {\colored[red]  test} \NC test \NC\NR
 +
  \NC test \NC {\colored[green] test} \NC test \NC\NR
 +
  \NC test \NC {\colored[blue]  test} \NC test \NC\NR
 +
  \NC test \NC {\colored[cyan]  test} \NC test \NC\NR
 +
\stoptabulate
 +
</texcode>
 +
 
  
Tabulate has no support for column spans but you could add this function yourself.
+
=Column Spans=
  
The code to do this depends on the tabulate setting and you have to know what
+
Tabulate has no support for column spans but you could add this
content what column setting you need.
+
function yourself.
 +
The code to do this depends on the tabulate setting and you have
 +
to know what content what column setting you need.
  
=== Single row columns ===
+
==Single row columns==
  
 
To span columns in cells with <code>l</code>, <code>r</code> or <code>c</code>
 
To span columns in cells with <code>l</code>, <code>r</code> or <code>c</code>
 
you could use <code>\span\omit\span\omit\span\omit</code> for each cell.
 
you could use <code>\span\omit\span\omit\span\omit</code> for each cell.
 
 
You could prevent these values you could them in a macro and use it with
 
You could prevent these values you could them in a macro and use it with
 
<code>\use{2}</code> or <code>\TWO</code> in the tabulate environment.
 
<code>\use{2}</code> or <code>\TWO</code> in the tabulate environment.
Line 144: Line 432:
 
|}
 
|}
  
=== Paragraph columns ===
+
== Paragraph columns ==
  
For spanned columns in cells with paragraphs you need a different implementation.
+
For spanned columns in cells with paragraphs you need a different
 +
implementation.
  
 
To use this macro you have to take care about a few things:
 
To use this macro you have to take care about a few things:
  
 
* You have to set a width for each cell
 
* You have to set a width for each cell
* The format for the spanned column is fixed and you have to change it in the macro
+
 
 +
* The format for the spanned column is fixed and you have to change it in the macro
  
 
{|
 
{|
Line 202: Line 492:
 
|}
 
|}
  
== More Features ==
+
=See also=
 +
 
 +
* More features are constantly added and documented only in the [[source:tabl-tbl.mkiv|source]].
 +
 
 +
* [[cmd:starttabulate|Command description]]
 +
 
 +
* [[TABLE|Natural Tables]]
  
... are documented only in the [[source:tabl-tbl.mkii|source]].
+
* [[cmd:starttable|Table environment]]
  
 
[[Category:Tables]]
 
[[Category:Tables]]

Revision as of 12:50, 8 December 2010

< Tables Overview | Table >


Summary

Tabulate is a versatile table environment. It supports paragraphs in cells, vertical rules (for those typographically less demanding jobs …), and colorization of those rules, the background of fields as well as the text itself.

Basic commands

The control sequence \starttabulate[#1] takes a layout string as optional argument. As is common with tables in TeX-based typesetting, this string (in its basic variant) consists primarily of the bar character (“|”) as delimiter for columns, and of the letters c, l, as well as r, denoting the alignment within cells of this row.

For instance consider a two-column table: if any text in the first column should be right aligned (real flushright) and the second column left aligned, the corresponding format string would be |l|r|. NB: those bars, as stated above, denote cell limits only – not vertical lines.

\starttabulate[|r|l|]
\HL
\NC {\bf format} \NC {\bf meaning}                    \NC\NR
\HL
\NC c      \NC centered                               \NC\NR
\NC l      \NC left aligned                           \NC\NR
\NC r      \NC right aligned                          \NC\NR
\NC w(1cm) \NC one line, fixed width                  \NC\NR
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR
\NC cg(.)  \NC align on a character                   \NC\NR
\HL
\stoptabulate
  • HL draws a horizontal rule,
  • NC marks a new column (or new cell),
  • NR starts new row.

It is generally not necessary to conclude lines with \NC\NR as \AR (for autorow) will do the job as well.

Spanning Multiple Pages

Tabulate may extend to adjacient pages if needed. To achieve this the argument split must be set to true. NB: the difference between setting and unsetting this argument may not be visible on the first few pages. Rather, it seems to affect the end of the environment.

\setuppapersize [XY][A4]
\setuppaper     [nx=2,ny=2]
\setuparranging [XY]
\setupbodyfont[10pt]

\starttext

\setuptabulate[split=yes]

\starttabulate
\dorecurse{2}{
  \NC test \NC \input tufte   \relax \NC \NR 
  \NC test \NC \input dawkins \relax \NC \NR 
}
\stoptabulate

\stoptext \endinput

Titles

A tabulating environment can have an optional name which will be repeated above at every page break that occurs inside the table. This name needs to be specified as the argument of the title key of \setuptabulate. The header key has to be set to text for this to work.

\setuptabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}]

\starttabulate
\dorecurse{2}{
  \NC Ed Tufte     \NC \input tufte   \relax \NC \NR
  \NC Dick Dawkins \NC \input dawkins \relax \NC \NR
}

Headers

Tabulate supports header rows that can be repeated over new table pages instead of the title. There is a separate environment \starttablehead where this header row has to be specified in advance of its use in a tabulation.

\setuptabulate[split=yes,header=repeat]

\starttabulatehead
  \HL
  \NC {\bf format char} \NC {\bf meaning} \AR
  \HL
\stoptabulatehead

\starttabulate[|r|l|]
    \NC c \NC centered      \AR
    \NC l \NC left aligned  \AR
    \NC r \NC right aligned \AR
\stoptabulate

Individualizing the Tabulate Look

Hans initially announced support for vertical lines and colors on the mailing list.[1]

Rules

Horizontal Rules

As already demonstrated above, the \HL statement inserts a hairline after the current line. This particularly useful when demarking header and footer rows or separated parts of a table that should not be as closely associated as the rows between the rules.

\starttabulate[|r|c|l|] 
\NC test \NC test \NC test \NC\NR 
\HL
\NC test \NC test \NC test \NC\NR 
\NC test \NC test \NC test \NC\NR 
\HL
\NC test \NC test \NC test \NC\NR 
\HL
\stoptabulate

Context supports different categories of rules that can be configured individually in order to discern various applications. Their behaviour accounts for the designated use, e. g. \ML (mid rules) are intended to be deployed between ordinary rows of the table body and will prevent page breaks – no way you’d end up with a rogue hairline desecrating the bottom of your page’s text area.

Type Description
\HL standard horizontal rule;
\FL first rule;
\ML mid rule;
\LL bottom rule;
\LL and \TL bottom rule;
\BL last rule.

Additionally, there is an options rulecolor for \setuptabulate that allows for those rules to be tinted.

\setuptabulate[rulecolor=red]

\starttabulate[|r|c|l|] 
    \FL
    \NC first row \NC test \NC test \NC\NR 
    \ML
    \NC rows in   \NC test \NC test \NC\NR 
    \NC between   \NC test \NC test \NC\NR 
    \LL           
    \NC last row  \NC test \NC test \NC\NR 
    \BL
\stoptabulate

Other types can be discovered in the source (tabl-tbl.mkiv).

Vertical Rules

The \VL command serves as a replacement for \NC to mark a cell border wherever a vertical rule may be desired (if they are to be desired at all from a typographical point of view).

\starttabulate[||||] 
    \NC test \VL test \VL test \VL\NR 
    \VL test \NC test \VL test \VL\NR 
    \VL test \VL test \NC test \VL\NR 
    \VL test \VL test \VL test \NC\NR 
\stoptabulate

Coloring

The following elements can be colorized: rules, cell backgrounds, and, obviously, common text.

Colorizing Rules

For horizontal rules see above.

For vertical rules, \VL takes a defined color as an optional argument.

\starttabulate[|r|c|l|] 
  \VL test \VL[red]    red rule    \VL test \VL \NR 
  \VL test \VL[green]  green rule  \VL test \VL \NR 
  \VL test \VL[blue]   blue rule   \VL test \VL \NR 
\stoptabulate

Colorizing Backgrounds

Backgrounds can be colorized either on column basis or individually by cell.

There are four color-specific control sequences:

CR color is applied to the background of the text and the remaining space on the right;
CC color is applied to the background of the text only;
CM color is applied to the background of the text and the remaining space on both sides;
CL color is applied to the background of the text and the remaining space on the left.

These are to complement the normal table layout expression (the first argument to \starttabulate. Thus, in order to colorize a four column table with the initial layout |c|c|c|c| it will have to be modified as follows:

\starttabulate[|CR{red}c|CC{yellow}c|CM{green}c|CL{blue}c|] 
    \NC test \NC test \NC test \NC test \NC \NR 
    \NC test \NC test \NC test \NC test \NC \NR 
    \NC test \NC test \NC test \NC test \NC \NR 
    \NC test \NC test \NC test \NC test \NC \NR 
\stoptabulate

Those control sequences, if applied within the table body, can replace the ordinary \NC, allowing individual cells to be colorized.

\starttabulate[|c|c|c|c|c|c|]
  \NC g \NC l \NC i \NC d \NC e \NC r \NC \NR 
  \NC g \NC l \NC i \CM[blue] d \NC e \NC r \NC \NR 
  \NC g \NC l \NC i \NC d \CM[blue] e \NC r \NC \NR 
  \NC g \NC l \CM[blue] i \CM[blue] d \CM[blue] e \NC r \NC \NR 
  \NC g \NC l \NC i \NC d \NC e \NC r \NC \NR 
\stoptabulate


Colorizing Cell Text

Normal text inside cells gets its color via the standard coloring commands.

\starttabulate[|r|c|l|] 
  \NC test \NC {\colored[red]   test} \NC test \NC\NR 
  \NC test \NC {\colored[green] test} \NC test \NC\NR 
  \NC test \NC {\colored[blue]  test} \NC test \NC\NR 
  \NC test \NC {\colored[cyan]  test} \NC test \NC\NR 
\stoptabulate


Column Spans

Tabulate has no support for column spans but you could add this function yourself. The code to do this depends on the tabulate setting and you have to know what content what column setting you need.

Single row columns

To span columns in cells with l, r or c you could use \span\omit\span\omit\span\omit for each cell. You could prevent these values you could them in a macro and use it with \use{2} or \TWO in the tabulate environment.

\def\tabulateuse#1%
  {\dorecurse{\numexpr2*#1-1\relax}{\span\omit}}

\appendtoks
  \let\use\tabulateuse
  \defineTABLEshorthands
\to \everytabulate

\starttext

\starttabulate[|l|Br|l|l|]
\NC a \NC b \NC c \NC d \NR
\NC 1 \NC 2 \TWO  \NC 4 \NR
\stoptabulate

\stoptext

Paragraph columns

For spanned columns in cells with paragraphs you need a different implementation.

To use this macro you have to take care about a few things:

  • You have to set a width for each cell
  • The format for the spanned column is fixed and you have to change it in the macro
\def\tabulateuse#1%
 {\dorecurse{\numexpr2*#1-1\relax}{\span\omit}\raggedright\ignorespaces}

\appendtoks
  \let\use\tabulateuse
  \defineTABLEshorthands
\to \everytabulate

\starttext

\starttabulate[|p(2cm)|p(3cm)|p(4cm)|]
\NC \dorecurse{10}{text } \NC \dorecurse{4}{Lorem Ipsum } \NC
\dorecurse{18}{text } \NC\NR
\NC \TWO Short text spanning two tabulate paragraphs. \NC
\dorecurse{17}{text } \NC\NR
\stoptabulate

\stoptext

See also

  • More features are constantly added and documented only in the source.