Changes

Jump to navigation Jump to search
add line and dash factors
< [[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 {{cmd|starttabulate}} is especially suited if you want to have a versatile table environment.It supports ''paragraphs '' in one cells, ''vertical rules'' (or moreforthose typographically less demanding jobs&nbsp;…) , and''colorization'' of those rules, the tabulate columnsbackground of fields as wellas the text itself.
'''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= The sample describes control sequence {{cmd|starttabulate|[#1]}} takes a layoutstring as optional argument.As is common with tables in TeX-based typesetting, this string(in its basic variant) consists primarily of the formatting characters''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 text in thefirst column should be right aligned (''real''[[Right and left|<tt>flushright</tt>]]) and the second columnleft 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*? - - No, I formatted it readably in my text editor. --HR-->{| ! width="55%"| ! width="10%"| ! width="35%"| |- | <texcode>\starttabulate[|r|l|lB|]\HL\NC {\bf format} \NC {\bf meaning} \NC Mk \NC\NR\HL\NC c \NC centered \NC \NC\NR\NC l \NC left aligned \NC \NC\NR\NC r \NC right aligned \NC \NC\NR\NC w(1cm) \NC one line, fixed width \NC \NC\NR\NC p(2cm) \NC paragraph, lines broken to fixed width \NC \NC\NR\NC cg(.) \NC align on a character \NC IV: cg{.} \NC\NR\NC m \NC math mode \NC IV only \NC\NR\NC b \NC before e.g. b{\star} \NC IV only \NC\NR\NC a \NC after, e.g. a{\percent} \NC IV only \NC\NR\HL\stoptabulate</texcode>||<context>\setuppapersize[A5]\starttabulate[|r|l|lB|]\HL\NC {\bf format} \NC {\bf meaning}\NC Mk \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</context>|} * {{cmd|HL}} draws a horizontal rule,* {{cmd|NC}} marks a new column (or new cell),* {{cmd|NS}} marka 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 thecurrent page-width. For example: if you want the previous tableto take up all the width and having the second column taking threequarters 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 since September 2021 supports wide cells: <context source=yes>\starttabulate[|r|l|c|]
\HL
\NC format 123 \NC meaning foo \NC\NR\HL\NC c \NC centered bar \NC\NR\NC l \NC left aligned NS[2][c] LMTX \NC\NR\NC r 123 \NC right aligned baz \NC\NR\NC w(1cm) \NC one line, fixed width \NC\NR\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR% You can leave out the bla \NC before \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=
 
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[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
</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 {{cmd|setuptabulate}}.
The <tt>header</tt> key has to be set to <em>text</em> for this
to work.
 
<context source=yes>
\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
</context>
 
<!--
- ==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 {{cmd|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 {{cmd|starttabulatehead}}[] instead.
 
{|
! width="55%"|
! width="10%"|
! width="35%"|
|-
| <texcode>
\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
</texcode>
|
| <context>
\setuppapersize[A5]
 
\setuptabulate[split=yes,header=repeat]
 
\starttabulatehead
\FL
\NC {\bf format char} \NC {\bf meaning} \AR
\LL
\stoptabulatehead
 
\starttabulate[|r|l|]
\NC c \NC centered \AR
\NC l \NC left aligned \AR
\NC r \NC right aligned \AR
\stoptabulate
</context>
|}
* Note the use of <tt>\FL</tt> and <tt>\LL</tt> in the tabulate header rather than <tt>\HL </tt> which is horizontal line* NC is new column a standard rule command (or new cellsee below)* NR is new rowthat tries to guess automatically its position.
The sample looks like this:=Individualizing the Tabulate Look=
Hans initially announced support for vertical lines and colors onthe mailing list. [http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html] ==Rules== ===Horizontal Rules=== As already demonstrated above, the <tt>\HL</tt> statement insertsa hairline after the current line.This particularly useful when demarking header and footer rows orseparated parts of a table that should not be as closelyassociated 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[|lr|c|l|]\NC test \NC test \NC test \NC\NR
\HL
\NC format test \NC meaning test \NC test \NC\NR \NC test \NC test \NC test \NC\NR
\HL
\NC c test \NC centered test \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% You can leave out the test \NC before \NR
\HL
\stoptabulate
</context>
|}
Context supports different categories of rules that can beconfigured individually in order to discern various applications.Their behaviour accounts for the designated use, e.g.<tt>\ML</tt> (mid rules) are intended to be deployed betweenordinary rows of the table body and will prevent page breaks&ndash; no way you’d end up with a rogue hairline desecratingthe bottom of your page’s text area.{|cellpadding="10" style= Column Spans ="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.|}
Tabulate has no support Additionally, there is an option <tt>rulecolor</tt> for column spans but you could add this function yourself{{cmd|setuptabulate}} that allows for those rules to be tinted.
The code to do this depends on the tabulate setting and you have to know what<texcode>content what column setting you need.\setuptabulate[rulecolor=red]
=== Single \starttabulate[|r|c|l|] \FL \NC first row columns ===\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>
To span columns in cells with <code>l</code>In LMTX, <code>r</code> the line commands understand one or <code>c</code>you could use <code>\span\omit\span\omit\span\omit</code> for each celltwo numerical parameters: the line factor and the dash factor.(The second is new as of 2024-02-22.)
You could prevent these values you could them <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([[source:tabl-tbl.mkiv|tabl-tbl.mkiv]]). ===Vertical Rules=== The {{cmd|VL}} command serves as a replacement for {{cmd|NC}}to mark a macro and use it withcell border wherever a vertical rule may be desired (ifthey are to be desired at all from a typographical point ofview). <codetexcode>\use{2}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</codetexcode> or  ==Coloring== The following elements can be colorized: rules, cell backgrounds,and, obviously, common text. ===Colorizing Rules=== For ''horizontal rules'' see above. For ''vertical rules'', {{cmd|VL}} takes a defined color as anoptional argument. <codetexcode>\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 \TWOVL test \VL \NR \stoptabulate</codetexcode> in the tabulate environment ===Colorizing Backgrounds & Text===Backgrounds and text can be colorized either on column basis orindividually by cell.
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
first argument to {{cmd|starttabulate}.
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>
\defstarttabulate[|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 \tabulateuse#1%NR { \NC test \NC test \dorecurse{NC test \numexpr2*#1-1NC test \relax}{NC \spanNR \omitstoptabulate</texcode> Those control sequences, if applied within the table body, canreplace the ordinary {{cmd|NC}}, allowing individual cells tobe 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>
'''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===
''Normal text'' inside cells gets its color via the
[[Color|standard coloring commands]], or by the
shorter variant described above.
 
<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>
 
== Vertical Distance Between Rows ==
 
<!--
There does not seem to be an official interface for
vertical skips.
Manually placed <code>\blank</code>s are
<code>\unskipped</code> on purpose.
However, as expected there is a token list
<code>\t_tabl_tabulate_every_after_row</code> that is
placed after a line is finished.
So, in order to get a vertical spacing of half a baseline
distance you can use this code:
 
<texcode>
\unprotect
\appendtoks
\letblank[halfline]\to \t_tabl_tabulate_every_after_row\protect</texcode> --> <context mode=mkiv source=yes>\starttabulate \useNC one \tabulateuseNC two \NC\NR \defineTABLEshorthandsNC two \NC three \NC\NR \to TB[halfline] \NC four \NC five \NC\NR \TB[line] \NC four \NC five \NC\NR \TB[1cm] \NC eight \NC nine \NC\NR \everytabulatestoptabulate</context>
\starttext=Using math mode= 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|Br|l|l|]\NC a HL\NC b NN 10e-3 \NC c \NC d NN 10e+3 \NR\NC 1 \NC 2 \TWO \NC 4 \NRHL
\stoptabulate
</texcode>
instead of <texcode>\stoptextstarttabulate[|l|l|]\HL\NC $10\cdot 10^{-3}$ \NC $10 \cdot 10^3$ \NR\HL\stoptabulate</texcode> 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>
=== Paragraph columns ===
For spanned columns in cells with paragraphs you need =Itemization or framed objects inside a different implementation.tabulation= The following issue is related to MkIV:
To use 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 macro you have . As a result two lines are typeset on top of each other. The solution is to take care about a few thingsadd the following statement to the preamble:<texcode>\tabulatesplitlinemode \plustwo</texcode>
* You have to set a width for each cell* The format for following code provided by Wolfgang Schuster demonstrates the spanned column is fixed problem: Compile with and you have to change it in without the macroline <tt>\tabulatesplitlinemode\plustwo</tt>
<texcode>
\deftabulatesplitlinemode \tabulateuse#1%plustwo\starttabulate[|p|] {\dorecurse{NCone \numexpr2*#1-1par\relax}{blank[penalty:10000]two \spanpar\omit}blank[penalty:10000]three\raggedrightNC\ignorespacesNR\stoptabulate</texcode> The same is true if you use {{cmd|framed}}or something that uses it internally, like [[Widgets]], within Tabulate.
\appendtoks \let\use\tabulateuse \defineTABLEshorthands\to \everytabulate=Combining enumerations and tabulations=
\starttext{{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[|p(4cm)|p(4cm)|p(6cm)||]\NC p \dorecurse{10}{text } NC \itemtag \NC q \dorecurse{8}{text } NC r \NC\NR\dorecurse{18}{text } NC p \NC \itemtag \NC q \NC r \NC\NR\NC p \TWO Short text spanning two tabulate paragraphs. NC \itemtag \NCq \NC r \NC \NR\dorecurse{22}{text } NC p \NC \itemtag \NC q \NC r \NC\NR
\stoptabulate
\stopitemize
</context>
<texcode>\stoptextstartitemize[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=
 
* More features are constantly added and documented in the {{src|tabl-tbl.mkiv|source}}.
* {{cmd|starttabulate}}, {{cmd|setuptabulate}}, {{cmd|definetabulate}}
* [[TABLE|Natural Tables]]
* {{cmd|starttable}}, <s>{{cmd|setuptable}}</s>
[[Category:Tables]]

Navigation menu