Difference between revisions of "Tabulate"
(→Colorizing Cell Text: vertical row distance) |
(remove MkII stuff, fix errors) |
||
(32 intermediate revisions by 14 users not shown) | |||
Line 10: | Line 10: | ||
as the text itself. | as the text itself. | ||
− | '''Warning''': When you want to use tables with macros use | + | '''Warning''': When you want to use tables with macros use {{cmd|starttable}} and \stoptable. {{cmd|starttabulate}} and \stoptabulate does not work correctly with macros. |
=Basic commands= | =Basic commands= | ||
− | The control sequence | + | The control sequence {{cmd|starttabulate|[#1]}} takes a layout |
string as optional argument. | string as optional argument. | ||
As is common with tables in TeX-based typesetting, this string | As is common with tables in TeX-based typesetting, this string | ||
Line 22: | Line 22: | ||
denoting the ''alignment'' within cells of this row. | denoting the ''alignment'' within cells of this row. | ||
− | For instance consider a two-column table: if | + | For instance consider a two-column table: if text in the |
first column should be right aligned (''real'' | 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 | left aligned, the corresponding format string would be | ||
<tt>|l|r|</tt>. | <tt>|l|r|</tt>. | ||
Line 30: | Line 30: | ||
– ''not'' vertical lines. | – ''not'' vertical lines. | ||
− | |||
− | |||
− | |||
− | |||
{| | {| | ||
! width="55%"| | ! width="55%"| | ||
Line 40: | Line 36: | ||
|- | |- | ||
| <texcode> | | <texcode> | ||
− | \starttabulate[|r|l|] | + | \starttabulate[|r|l|lB|] |
\HL | \HL | ||
− | \NC {\bf format} \NC {\bf meaning} | + | \NC {\bf format} \NC {\bf meaning} \NC\NR |
\HL | \HL | ||
\NC c \NC centered \NC\NR | \NC c \NC centered \NC\NR | ||
Line 48: | Line 44: | ||
\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 \NC paragraph, remaining 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 | ||
+ | \NC m \NC math mode \NC\NR | ||
+ | \NC b \NC before, e.g. b{\star} \NC\NR | ||
+ | \NC a \NC after, e.g. a{\percent} \NC\NR | ||
\HL | \HL | ||
\stoptabulate | \stoptabulate | ||
Line 56: | Line 56: | ||
|<context> | |<context> | ||
\setuppapersize[A5] | \setuppapersize[A5] | ||
− | \starttabulate[|r|l|] | + | \starttabulate[|r|l|lB|] |
\HL | \HL | ||
− | \NC {\bf format} \NC {\bf meaning} | + | \NC {\bf format} \NC {\bf meaning} \NC\NR |
\HL | \HL | ||
\NC c \NC centered \NC\NR | \NC c \NC centered \NC\NR | ||
Line 64: | Line 64: | ||
\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 \NC paragraph, remaining 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 | ||
+ | \NC m \NC math mode \NC\NR | ||
+ | \NC b \NC before, e.g. b{\star} \NC\NR | ||
+ | \NC a \NC after, e.g. a{\percent} \NC\NR | ||
\HL | \HL | ||
\stoptabulate | \stoptabulate | ||
Line 71: | Line 75: | ||
|} | |} | ||
− | * | + | * {{cmd|HL}} draws a horizontal rule, |
− | * | + | * {{cmd|NC}} marks a new column (or new cell), |
− | * | + | * {{cmd|NS}} marks a new cell that spans more than one column (LMTX only), |
− | * | + | * {{cmd|NN}} marks a new math column/cell (see below), |
+ | * {{cmd|NR}} starts a new row, | ||
+ | * {{cmd|NB}} starts a new row as a block (avoids page breaking inside of a block, to keep some lines together), | ||
+ | * {{cmd|TB}} (= "Table Blank") adds some vertical space between rows — see an example below, | ||
+ | * {{cmd|VL}} (instead of {{cmd|NC}}) draws a vertical rule — for more info see below. | ||
+ | |||
+ | When using fixed width, you can use values relative to the | ||
+ | current page width. For example: if you want the previous table | ||
+ | to take up all the width and having the second column taking three | ||
+ | quarters of the space, change the {{cmd|starttabulate}} to: | ||
+ | <texcode> | ||
+ | \starttabulate[|rw(.25\textwidth)|lw(.75\textwidth)|] | ||
+ | </texcode> | ||
+ | (Mistake: This doesn’t account for the width of the column distance!) | ||
+ | |||
+ | =Horizontal centering table on the page= | ||
+ | |||
+ | <context source=yes> | ||
+ | This is a very long text, longer than the width of the table. | ||
+ | It must be long enough to flow to the next line to see the effect. | ||
+ | |||
+ | \placetable[force,none]{}{% | ||
+ | \starttabulate[|r|l|] | ||
+ | \HL | ||
+ | \NC I want this table \NC aligned in the center.\NC\NR | ||
+ | \HL | ||
+ | \stoptabulate | ||
+ | }</context> | ||
+ | |||
+ | This can also be done with the start/stop syntax: | ||
+ | |||
+ | <context source=yes> | ||
+ | This is a very long text, longer than the width of the table. | ||
+ | It must be long enough to flow to the next line to see the effect. | ||
+ | |||
+ | \startplacetable[location=force,number=no] | ||
+ | \starttabulate[|r|l|] | ||
+ | \HL | ||
+ | \NC I want this table \NC aligned in the center.\NC\NR | ||
+ | \HL | ||
+ | \stoptabulate | ||
+ | \stopplacetable | ||
+ | </context> | ||
+ | =Spanning columns= | ||
− | + | Only LMTX supports wide cells (since September 2021): | |
− | |||
− | |||
− | |||
− | \starttabulate[| | + | <context source=yes> |
+ | \starttabulate[|r|l|c|] | ||
+ | \HL | ||
+ | \NC 123 \NC foo \NC bar \NC\NR | ||
+ | \NS[2][c] LMTX \NC\NR | ||
+ | \NC 123 \NC baz \NC bla \NC\NR | ||
+ | \HL | ||
+ | \stoptabulate | ||
+ | </context> | ||
+ | The two parameters of {{cmd|NS}} are the number of additional columns (i.e. 1 of you want to span 2 columns), and the formatting for it. | ||
− | + | This works only with single-line cells, i.e. not with “p” columns. | |
− | |||
− | |||
=Spanning Multiple Pages= | =Spanning Multiple Pages= | ||
Line 94: | Line 145: | ||
To achieve this the argument <tt>split</tt> must be set to | To achieve this the argument <tt>split</tt> must be set to | ||
''true''. | ''true''. | ||
+ | |||
''NB'': the difference between setting and unsetting this | ''NB'': the difference between setting and unsetting this | ||
argument may not be visible on the first few pages. Rather, it | argument may not be visible on the first few pages. Rather, it | ||
Line 129: | Line 181: | ||
repeated above at every page break that occurs inside the table. | repeated above at every page break that occurs inside the table. | ||
This name needs to be specified as the argument of the | This name needs to be specified as the argument of the | ||
− | <tt>title</tt> key of | + | <tt>title</tt> key of {{cmd|setuptabulate}}. |
The <tt>header</tt> key has to be set to <em>text</em> for this | The <tt>header</tt> key has to be set to <em>text</em> for this | ||
to work. | to work. | ||
<context source=yes> | <context source=yes> | ||
− | \setuppapersize[A10, landscape][A8, landscape] | + | \setuppapersize[A10,landscape][A8,landscape] |
\setuppaper[nx=2,ny=2] | \setuppaper[nx=2,ny=2] | ||
\setuparranging[XY] | \setuparranging[XY] | ||
Line 145: | Line 197: | ||
[split=yes, | [split=yes, | ||
header=text, | header=text, | ||
− | title={\color[red] Fenchurch St. Paul}, | + | title={\color[red]{Fenchurch St. Paul}\strut}, |
frame=on] | frame=on] | ||
+ | \starttext | ||
\starttabulate[|p(1.2cm)|p(1.2cm)|] | \starttabulate[|p(1.2cm)|p(1.2cm)|] | ||
\dorecurse{6}{ | \dorecurse{6}{ | ||
Line 156: | Line 209: | ||
} | } | ||
\stoptabulate | \stoptabulate | ||
+ | \stoptext | ||
</context> | </context> | ||
Line 169: | Line 223: | ||
Tabulate supports header rows that can be repeated over new table | Tabulate supports header rows that can be repeated over new table | ||
pages instead of the title. | pages instead of the title. | ||
− | There is a separate environment | + | There is a separate environment {{cmd|starttabulatehead}} where |
this header row has to be specified in advance of its use in a | this header row has to be specified in advance of its use in a | ||
tabulation. | tabulation. | ||
+ | |||
+ | In ConTeXt MkIV the command requires an additional [], thus you need | ||
+ | to write {{cmd|starttabulatehead}}[] instead. | ||
{| | {| | ||
Line 182: | Line 239: | ||
\starttabulatehead | \starttabulatehead | ||
− | \ | + | \FL |
− | \NC {\bf format char} \NC {\bf meaning} \AR | + | \NC {\bf format char} \NC {\bf meaning} \NC \AR |
− | \ | + | \LL |
\stoptabulatehead | \stoptabulatehead | ||
\starttabulate[|r|l|] | \starttabulate[|r|l|] | ||
− | \NC c \NC centered \AR | + | \NC c \NC centered \NC \AR |
− | \NC l \NC left aligned \AR | + | \NC l \NC left aligned \NC \AR |
− | \NC r \NC right aligned \AR | + | \NC r \NC right aligned \NC \AR |
\stoptabulate | \stoptabulate | ||
</texcode> | </texcode> | ||
Line 200: | Line 257: | ||
\starttabulatehead | \starttabulatehead | ||
− | \ | + | \FL |
\NC {\bf format char} \NC {\bf meaning} \AR | \NC {\bf format char} \NC {\bf meaning} \AR | ||
− | \ | + | \LL |
\stoptabulatehead | \stoptabulatehead | ||
Line 212: | Line 269: | ||
</context> | </context> | ||
|} | |} | ||
+ | |||
+ | Note the use of <tt>\FL</tt> and <tt>\LL</tt> in the tabulate header rather than <tt>\HL</tt> which is a standard rule command (see below) that tries to guess automatically its position. | ||
=Individualizing the Tabulate Look= | =Individualizing the Tabulate Look= | ||
Hans initially announced support for vertical lines and colors on | Hans initially announced support for vertical lines and colors on | ||
− | the mailing list.[http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html] | + | the mailing list. [http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html] |
==Rules== | ==Rules== | ||
Line 259: | Line 318: | ||
Context supports different categories of rules that can be | Context supports different categories of rules that can be | ||
configured individually in order to discern various applications. | configured individually in order to discern various applications. | ||
− | Their behaviour accounts for the designated use, e. | + | Their behaviour accounts for the designated use, e.g. |
<tt>\ML</tt> (mid rules) are intended to be deployed between | <tt>\ML</tt> (mid rules) are intended to be deployed between | ||
ordinary rows of the table body and will prevent page breaks | ordinary rows of the table body and will prevent page breaks | ||
Line 280: | Line 339: | ||
|} | |} | ||
− | Additionally, there is an | + | Additionally, there is an option <tt>rulecolor</tt> for |
− | + | {{cmd|setuptabulate}} that allows for those rules to be tinted. | |
<texcode> | <texcode> | ||
Line 297: | Line 356: | ||
\stoptabulate | \stoptabulate | ||
</texcode> | </texcode> | ||
+ | |||
+ | In LMTX, the line commands understand one or two numerical parameters: the line factor and the dash factor. (The second is new as of 2024-02-22.) | ||
+ | |||
+ | <context source="yes"> | ||
+ | \starttabulate | ||
+ | \FL[1,2] % linefactor (old) dashfactor (new) | ||
+ | \NC test \NC test and test and test and done \NC \NR | ||
+ | \ML[1,1] | ||
+ | \NC test \NC test and test and test and done \NC \NR | ||
+ | \NC test \NC test and test and test and done \NC \NR | ||
+ | \NC test \NC test and test and test and done \NC \NR | ||
+ | \LL[1,10] | ||
+ | \stoptabulate | ||
+ | </context> | ||
Other types can be discovered in the source | Other types can be discovered in the source | ||
Line 303: | Line 376: | ||
===Vertical Rules=== | ===Vertical Rules=== | ||
− | The | + | The {{cmd|VL}} command serves as a replacement for {{cmd|NC}} |
to mark a cell border wherever a vertical rule may be desired (if | 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 | they are to be desired at all from a typographical point of | ||
Line 326: | Line 399: | ||
For ''horizontal rules'' see above. | For ''horizontal rules'' see above. | ||
− | For ''vertical rules'', | + | For ''vertical rules'', {{cmd|VL}} takes a defined color as an |
optional argument. | optional argument. | ||
Line 337: | Line 410: | ||
</texcode> | </texcode> | ||
− | ===Colorizing Backgrounds=== | + | ===Colorizing Backgrounds & Text=== |
− | + | Backgrounds and text can be colorized either on column basis or | |
individually by cell. | individually by cell. | ||
− | There are | + | There are five color-specific control sequences: |
{| | {| | ||
− | | | + | |{{cmd|CR}} || color is applied to the background of the text and the remaining space on the right. |
+ | |- | ||
+ | |{{cmd|CC}} || color is applied to the background of the text only. | ||
|- | |- | ||
− | | | + | |{{cmd|CM}} || color is applied to the background of the text and the remaining space on both sides. |
|- | |- | ||
− | | | + | |{{cmd|CL}} || color is applied to the background of the text and the remaining space on the left. |
|- | |- | ||
− | | | + | |{{cmd|CT}} || color is applied to the text itself - in other words, the "foreground color." |
|} | |} | ||
These are to complement the normal table layout expression (the | These are to complement the normal table layout expression (the | ||
− | first argument to | + | first argument to {{cmd|starttabulate}. |
Thus, in order to colorize a four column table with the initial | 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: | layout <tt>|c|c|c|c|</tt> it will have to be modified as follows: | ||
Line 365: | Line 440: | ||
Those control sequences, if applied within the table body, can | Those control sequences, if applied within the table body, can | ||
− | replace the ordinary | + | replace the ordinary {{cmd|NC}}, allowing individual cells to |
be colorized. | be colorized. | ||
<texcode> | <texcode> | ||
Line 377: | Line 452: | ||
</texcode> | </texcode> | ||
+ | '''caveat emptor'''! The background coloring does apply only to | ||
+ | the ''first'' row of a paragraph cell. Any other cell will come | ||
+ | out colorless. If you need to color an entire multi-line cell, | ||
+ | you will need to switch to another | ||
+ | [[Tables Overview|tabulation variant]]. | ||
===Colorizing Cell Text=== | ===Colorizing Cell Text=== | ||
''Normal text'' inside cells gets its color via the | ''Normal text'' inside cells gets its color via the | ||
− | [[ | + | [[Color|standard coloring commands]], or by the |
+ | shorter variant described above. | ||
<texcode> | <texcode> | ||
Line 393: | Line 474: | ||
== Vertical Distance Between Rows == | == Vertical Distance Between Rows == | ||
+ | <!-- | ||
There does not seem to be an official interface for | There does not seem to be an official interface for | ||
vertical skips. | vertical skips. | ||
Line 409: | Line 491: | ||
\to \t_tabl_tabulate_every_after_row | \to \t_tabl_tabulate_every_after_row | ||
\protect | \protect | ||
+ | </texcode> | ||
− | </ | + | --> |
+ | |||
+ | <context mode=mkiv source=yes> | ||
+ | \starttabulate | ||
+ | \NC one \NC two \NC\NR | ||
+ | \NC two \NC three \NC\NR | ||
+ | \TB[halfline] | ||
+ | \NC four \NC five \NC\NR | ||
+ | \TB[line] | ||
+ | \NC four \NC five \NC\NR | ||
+ | \TB[1cm] | ||
+ | \NC eight \NC nine \NC\NR | ||
+ | \stoptabulate | ||
+ | </context> | ||
=Using math mode= | =Using math mode= | ||
− | If you want to display numerics, you can simply use | + | If you want to display numerics, you can simply use {{cmd|NN}} for a new column instead of {{cmd|NC}}. This command works similar to the [http://www.pragma-ade.nl/general/magazines/mag-0003.pdf digit-module]. Therefore you can also abbreviate: |
<texcode>\starttabulate[|l|l|] | <texcode>\starttabulate[|l|l|] | ||
Line 435: | Line 531: | ||
although both variants do work. | although both variants do work. | ||
+ | If you always need math in one column, consider math mode columns: | ||
+ | |||
+ | <texcode> | ||
+ | \starttabulate[|m|m|] | ||
+ | \HL | ||
+ | \NC 10e-3 \NC 10e+3 \NR | ||
+ | \HL | ||
+ | \stoptabulate | ||
+ | </texcode> | ||
− | |||
− | + | =Itemization or framed objects inside a tabulation= | |
− | The following issue is related to | + | The following issue is related to MkIV: |
When using an itemization inside a tabulation where one uses also the | When using an itemization inside a tabulation where one uses also the | ||
− | + | {{cmd|head}} 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: | |
<texcode>\tabulatesplitlinemode \plustwo</texcode> | <texcode>\tabulatesplitlinemode \plustwo</texcode> | ||
Line 461: | Line 565: | ||
</texcode> | </texcode> | ||
+ | The same is true if you use {{cmd|framed}} or something that uses it internally, like [[Widgets]], within Tabulate. | ||
+ | |||
+ | =Combining enumerations and tabulations= | ||
+ | |||
+ | {{cmd|NI}} (new item) exists since 2017-09-25. {{cmd|itemtag}} is old, but undocumented. Source: http://source.contextgarden.net/tex/context/base/mkiv/strc-itm.mkvi?search=itemtag | ||
+ | |||
+ | <context mode=mkiv source=yes> | ||
+ | \startitemize[n] | ||
+ | \starttabulate[|||||] | ||
+ | \NC p \NC \itemtag \NC q \NC r \NC \NR | ||
+ | \NC p \NC \itemtag \NC q \NC r \NC \NR | ||
+ | \NC p \NC \itemtag \NC q \NC r \NC \NR | ||
+ | \NC p \NC \itemtag \NC q \NC r \NC \NR | ||
+ | \stoptabulate | ||
+ | \stopitemize | ||
+ | </context> | ||
+ | |||
+ | <texcode> | ||
+ | \startitemize[n] | ||
+ | \starttabulate[|||||] | ||
+ | \NI x \NC y \NC z \NC \NR | ||
+ | \NI x \NC y \NC z \NC \NR | ||
+ | \NI x \NC y \NC z \NC \NR | ||
+ | \NI x \NC y \NC z \NC \NR | ||
+ | \stoptabulate | ||
+ | \stopitemize | ||
+ | |||
+ | \startitemize[n] | ||
+ | \starttabulate[|||||] | ||
+ | \NI b \NC c \NC d \NC \NR | ||
+ | \NC a \NI c \NC d \NC \NR | ||
+ | \NC a \NC b \NI d \NC \NR | ||
+ | \NC a \NC b \NC c \NI \NR | ||
+ | \stoptabulate | ||
+ | \stopitemize | ||
+ | </texcode> | ||
+ | |||
+ | =EQ option within table= | ||
+ | |||
+ | EQ option defines text which will be placed by \EQ column separator. | ||
+ | Source: https://www.mail-archive.com/ntg-context@ntg.nl/msg95207.html | ||
+ | |||
+ | <context mode=mkiv source=yes> | ||
+ | \starttabulate[|l|r|r|][EQ={=}] | ||
+ | \NC DC \EQ 3.20 bbl \EQ 420 ft \NC\NR | ||
+ | \NC HWDP \EQ 3.90 bbl \EQ 450 ft \NC\NR | ||
+ | \NC DP \EQ 34.63 bbl \EQ 2.037 ft \NC\NR | ||
+ | \NC DC \EQ 41.73 bbl \EQ 2.907 ft \NC\NR | ||
+ | \stoptabulate | ||
+ | </context> | ||
=See also= | =See also= | ||
* More features are constantly added and documented in the {{src|tabl-tbl.mkiv|source}}. | * More features are constantly added and documented in the {{src|tabl-tbl.mkiv|source}}. | ||
− | * {{cmd|starttabulate}} | + | * {{cmd|starttabulate}}, {{cmd|setuptabulate}}, {{cmd|definetabulate}} |
* [[TABLE|Natural Tables]] | * [[TABLE|Natural Tables]] | ||
− | * {{cmd|starttable}} | + | * {{cmd|starttable}}, <s>{{cmd|setuptable}}</s> |
[[Category:Tables]] | [[Category:Tables]] |
Latest revision as of 14:25, 15 May 2024
< Tables Overview | Table >
Contents
Summary
\starttabulate 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.
Warning: When you want to use tables with macros use \starttable and \stoptable. \starttabulate and \stoptabulate does not work correctly with macros.
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 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|lB|] \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 \NC paragraph, remaining 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 m \NC math mode \NC\NR \NC b \NC before, e.g. b{\star} \NC\NR \NC a \NC after, e.g. a{\percent} \NC\NR \HL \stoptabulate |
- \HL draws a horizontal rule,
- \NC marks a new column (or new cell),
- \NS marks a new cell that spans more than one column (LMTX only),
- \NN marks a new math column/cell (see below),
- \NR starts a new row,
- \NB starts a new row as a block (avoids page breaking inside of a block, to keep some lines together),
- \TB (= "Table Blank") adds some vertical space between rows — see an example below,
- \VL (instead of \NC) draws a vertical rule — for more info see below.
When using fixed width, you can use values relative to the current page width. For example: if you want the previous table to take up all the width and having the second column taking three quarters of the space, change the \starttabulate to:
\starttabulate[|rw(.25\textwidth)|lw(.75\textwidth)|]
(Mistake: This doesn’t account for the width of the column distance!)
Horizontal centering table on the page
This is a very long text, longer than the width of the table. It must be long enough to flow to the next line to see the effect. \placetable[force,none]{}{% \starttabulate[|r|l|] \HL \NC I want this table \NC aligned in the center.\NC\NR \HL \stoptabulate }
This can also be done with the start/stop syntax:
This is a very long text, longer than the width of the table. It must be long enough to flow to the next line to see the effect. \startplacetable[location=force,number=no] \starttabulate[|r|l|] \HL \NC I want this table \NC aligned in the center.\NC\NR \HL \stoptabulate \stopplacetable
Spanning columns
Only LMTX supports wide cells (since September 2021):
\starttabulate[|r|l|c|] \HL \NC 123 \NC foo \NC bar \NC\NR \NS[2][c] LMTX \NC\NR \NC 123 \NC baz \NC bla \NC\NR \HL \stoptabulate
The two parameters of \NS are the number of additional columns (i.e. 1 of you want to span 2 columns), and the formatting for it.
This works only with single-line cells, i.e. not with “p” columns.
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[A10, landscape][A8, landscape] \setuppaper[nx=2,ny=2] \setuparranging[XY] \switchtobodyfont[5pt] \setuppagenumbering[location={header,inright}] \showframe[edge] \setuptabulate [split=yes, header=text, title={\color[red] Fenchurch St. Paul}, frame=on] \starttabulate[|p(1.2cm)|p(1.2cm)|] \dorecurse{6}{ \NC Bells: \NC Tin tan din dan bim bam bom bo \NC\NR \HL \NC Name: \NC Tailor Paul \NC \NR \HL } \stoptabulate
internal error: convert failed
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.
\setuppapersize[A10,landscape][A8,landscape] \setuppaper[nx=2,ny=2] \setuparranging[XY] \switchtobodyfont[5pt] \setuppagenumbering[location={header,inright}] \showframe[edge] \setuptabulate [split=yes, header=text, title={\color[red]{Fenchurch St. Paul}\strut}, frame=on] \starttext \starttabulate[|p(1.2cm)|p(1.2cm)|] \dorecurse{6}{ \NC Bells: \NC Tin tan din dan bim bam bom bo \NC\NR \HL \NC Name: \NC Tailor Paul \NC \NR \HL } \stoptabulate \stoptext
Headers
Tabulate supports header rows that can be repeated over new table pages instead of the title. There is a separate environment \starttabulatehead where this header row has to be specified in advance of its use in a tabulation.
In ConTeXt MkIV the command requires an additional [], thus you need to write \starttabulatehead[] instead.
\setuptabulate[split=yes,header=repeat] \starttabulatehead \FL \NC {\bf format char} \NC {\bf meaning} \NC \AR \LL \stoptabulatehead \starttabulate[|r|l|] \NC c \NC centered \NC \AR \NC l \NC left aligned \NC \AR \NC r \NC right aligned \NC \AR \stoptabulate |
Note the use of \FL and \LL in the tabulate header rather than \HL which is a standard rule command (see below) that tries to guess automatically its position.
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 option 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
In LMTX, the line commands understand one or two numerical parameters: the line factor and the dash factor. (The second is new as of 2024-02-22.)
\starttabulate \FL[1,2] % linefactor (old) dashfactor (new) \NC test \NC test and test and test and done \NC \NR \ML[1,1] \NC test \NC test and test and test and done \NC \NR \NC test \NC test and test and test and done \NC \NR \NC test \NC test and test and test and done \NC \NR \LL[1,10] \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 & Text
Backgrounds and text can be colorized either on column basis or individually by cell.
There are five 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. |
\CT | color is applied to the text itself - in other words, the "foreground color." |
These are to complement the normal table layout expression (the first argument to {{cmd|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
caveat emptor! The background coloring does apply only to the first row of a paragraph cell. Any other cell will come out colorless. If you need to color an entire multi-line cell, you will need to switch to another tabulation variant.
Colorizing Cell Text
Normal text inside cells gets its color via the standard coloring commands, or by the shorter variant described above.
\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
Vertical Distance Between Rows
\starttabulate \NC one \NC two \NC\NR \NC two \NC three \NC\NR \TB[halfline] \NC four \NC five \NC\NR \TB[line] \NC four \NC five \NC\NR \TB[1cm] \NC eight \NC nine \NC\NR \stoptabulate
Using math mode
If you want to display numerics, you can simply use \NN for a new column instead of \NC. This command works similar to the digit-module. Therefore you can also abbreviate:
\starttabulate[|l|l|] \HL \NN 10e-3 \NN 10e+3 \NR \HL \stoptabulate
instead of
\starttabulate[|l|l|] \HL \NC $10\cdot 10^{-3}$ \NC $10 \cdot 10^3$ \NR \HL \stoptabulate
although both variants do work.
If you always need math in one column, consider math mode columns:
\starttabulate[|m|m|] \HL \NC 10e-3 \NC 10e+3 \NR \HL \stoptabulate
Itemization or framed objects inside a tabulation
The following issue is related to MkIV:
When using an itemization inside a tabulation where one uses also the \head 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:
\tabulatesplitlinemode \plustwo
The following code provided by Wolfgang Schuster demonstrates the problem: Compile with and without the line \tabulatesplitlinemode\plustwo
\tabulatesplitlinemode \plustwo \starttabulate[|p|] \NC one \par \blank[penalty:10000] two \par \blank[penalty:10000] three \NC\NR \stoptabulate
The same is true if you use \framed or something that uses it internally, like Widgets, within Tabulate.
Combining enumerations and tabulations
\NI (new item) exists since 2017-09-25. \itemtag is old, but undocumented. Source: http://source.contextgarden.net/tex/context/base/mkiv/strc-itm.mkvi?search=itemtag
\startitemize[n] \starttabulate[|||||] \NC p \NC \itemtag \NC q \NC r \NC \NR \NC p \NC \itemtag \NC q \NC r \NC \NR \NC p \NC \itemtag \NC q \NC r \NC \NR \NC p \NC \itemtag \NC q \NC r \NC \NR \stoptabulate \stopitemize
\startitemize[n] \starttabulate[|||||] \NI x \NC y \NC z \NC \NR \NI x \NC y \NC z \NC \NR \NI x \NC y \NC z \NC \NR \NI x \NC y \NC z \NC \NR \stoptabulate \stopitemize \startitemize[n] \starttabulate[|||||] \NI b \NC c \NC d \NC \NR \NC a \NI c \NC d \NC \NR \NC a \NC b \NI d \NC \NR \NC a \NC b \NC c \NI \NR \stoptabulate \stopitemize
EQ option within table
EQ option defines text which will be placed by \EQ column separator. Source: https://www.mail-archive.com/ntg-context@ntg.nl/msg95207.html
\starttabulate[|l|r|r|][EQ={=}] \NC DC \EQ 3.20 bbl \EQ 420 ft \NC\NR \NC HWDP \EQ 3.90 bbl \EQ 450 ft \NC\NR \NC DP \EQ 34.63 bbl \EQ 2.037 ft \NC\NR \NC DC \EQ 41.73 bbl \EQ 2.907 ft \NC\NR \stoptabulate
See also
- More features are constantly added and documented in the source.
- \starttabulate, \setuptabulate, \definetabulate
- Natural Tables
- \starttable,
\setuptable