Changes

Jump to navigation Jump to search
3,837 bytes added ,  10:38, 23 August 2020
m
removed some old comments
=Summary=
[[{{cmd:|starttabulate|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.
 
'''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 control sequence <tt>\{{cmd|starttabulate|[#1]</tt> }} takes a layout
string as optional argument.
As is common with tables in TeX-based typesetting, this string
For instance consider a two-column table: if any text in the
first column should be right aligned (''real''
[[right Right and left|<tt>flushright</tt>]]) and the second column
left aligned, the corresponding format string would be
<tt>|l|r|</tt>.
- 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
-->
{|
|-
| <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
|
|<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 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
|}
* <tt>{{cmd|HL</tt> }} draws a horizontal rule,* <tt>{{cmd|NC</tt> }} marks a new column (or new cell),* {{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 tabletake up all the width and having the second column taking threequarters of the space, change the {{cmd|starttabulate}} to:<tttexcode>NR\starttabulate[|rw(.25\textwidth)|lw(.75\textwidth)|]</tttexcode> starts new row.(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 is generally not necessary must be long enough to flow to the next line to conclude lines withsee the effect. \placetable[force,none]{}{% \starttabulate[|r|l|] \HL<tt> \NC I want this table \NC aligned in the center.\NC\NR \HL \stoptabulate}</ttcontext> as <tt>\AR< This can also be done with the start/tt> (for stop syntax: <emcontext source=yes>This is a</em>uto<em>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</emcontext>ow)will do the job as well.
=Spanning Multiple Pages=
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 [XYA10, landscape][A4A8, landscape]\setuppaper [nx=2,ny=2]\setuparranging [XY]\setupbodyfont[10pt]
\starttextswitchtobodyfont[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{26}{ \NC test Bells: \NC \input tufte \relax Tin tan din dan bim bam bom bo \NC \NR \HL \NC test Name: \NC \input dawkins \relax Tailor Paul \NC \NR \HL
}
\stoptabulate
</context>
\stoptext \endinput
</context>
==Titles==
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>\{{cmd|setuptabulate</tt>}}.
The <tt>header</tt> key has to be set to <em>text</em> for this
to work.
<texcodecontext source=yes>\setuptabulatesetuppapersize[A10, landscape][split=yesA8,headerlandscape]\setuppaper[nx=text2,titleny={2]\sc Table Titles Undisclosed!}setuparranging[XY]
\starttabulateswitchtobodyfont[5pt]\dorecursesetuppagenumbering[location={2header,inright}{ \NC Ed Tufte \NC \input tufte \relax \NC \NR] \NC Dick Dawkins \NC \input dawkins \relax \NC \NR}</texcode>showframe[edge]
<context>\setuptabulate\setuppapersize [XY][A4]split=yes,\setuppaper [nxheader=2text,ny title=2{\color[red]Fenchurch St. Paul},\setuparranging [XY frame=on]
\starttext \setuptabulatestarttabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}|p(1.2cm)|p(1.2cm)|\starttabulate\dorecurse{26}{ \NC Ed Tufte Bells: \NC \input tufte \relax Tin tan din dan bim bam bom bo \NC \NR \HL \NC Dick Dawkins Name: \NC \input dawkins \relax Tailor Paul \NC \NR \HL
}
\stoptabulate
 
\stoptext \endinput
</context>
- “\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> {{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.
{|
\starttabulatehead
\HLFL \NC {\bf format char} \NC {\bf meaning} \NC \AR \HLLL
\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
\HLFL
\NC {\bf format char} \NC {\bf meaning} \AR
\HLLL
\stoptabulatehead
</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=
Hans initially announced support for vertical lines and colors on
the mailing list.[http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html]
==Rules==
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
|}
Additionally, there is an options option <tt>rulecolor</tt> for<tt>\{{cmd|setuptabulate</tt> }} that allows for those rules to be tinted.
<texcode>
===Vertical Rules===
The <tt>\{{cmd|VL</tt> }} command serves as a replacement for <tt>\{{cmd|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
For ''horizontal rules'' see above.
For ''vertical rules'', <tt>\{{cmd|VL</tt> }} takes a defined color as an
optional argument.
</texcode>
===Colorizing Backgrounds& Text===''Backgrounds'' and text can be colorized either on column basis or
individually by cell.
There are four five color-specific control sequences:
{|
|<tt>{{cmd|CR</tt> }} || 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.
|-
|<tt>CC</tt> {{cmd|CM}} || color is applied to the background of the text only; and the remaining space on both sides.
|-
|<tt>CM</tt> {{cmd|CL}} || color is applied to the background of the text and the remaining space on both sides;the left.
|-
|<tt>CL</tt> {{cmd|CT}} || color is applied to the background of the text and itself - in other words, the remaining space on the left"foreground color."
|}
These are to complement the normal table layout expression (the
first argument to <tt>\{{cmd|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:
Those control sequences, if applied within the table body, can
replace the ordinary <tt>\{{cmd|NC</tt>}}, allowing individual cells to
be colorized.
<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===
''Normal text'' inside cells gets its color via the
[[colorsColor|standard coloring commands]], or by the shorter variant described above.
<texcode>
</texcode>
== Vertical Distance Between Rows ==
=Column Spans=<!--There does not seem to be an official interface forvertical 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 isplaced after a line is finished.So, in order to get a vertical spacing of half a baselinedistance you can use this code:
Tabulate has no support for column spans but you could add this<texcode>function yourself.\unprotectThe code \appendtoks \blank[halfline]\to do this depends on the tabulate setting and you have\t_tabl_tabulate_every_after_row\protectto know what content what column setting you need.</texcode>
==Single row columns==-->
To span columns in cells with <code>l</code>, <code>r</code> or <code>c</codecontext mode=mkiv source=yes>you could use <code>\spanstarttabulate \NC one \NC two \NC\NR \NC two \NC three \NC\NR \TB[halfline] \NC four \NC five \omitNC\spanNR \omitTB[line] \spanNC four \omit</code> for each cell.NC five \NC\NR You could prevent these values you could them in a macro and use it with \TB[1cm]<code> \NC eight \NC nine \NC\use{2}</code> or <code>NR \TWOstoptabulate</codecontext> in the tabulate environment.
{| ! width="45%"| ! widthUsing math mode="10%"| ! width="45%"| |- | <texcode>\def\tabulateuse#1% If you want to display numerics, you can simply use {\dorecurse{\numexpr2*#1-1\relaxcmd|NN}}for a new column instead of {\span\omit{cmd|NC}}. This command works similar to the [http://www.pragma-ade.com/general/magazines/mag-0003.pdf digit-module]. Therefore you can also abbreviate:
<texcode>\appendtoksstarttabulate[|l|l|] \letHL\NN 10e-3 \useNN 10e+3 \tabulateuseNR \defineTABLEshorthandsHL\to \everytabulatestoptabulate</texcode>
\starttextinstead of
<texcode>\starttabulate[|l|Br|l|l|]\HL\NC a $10\NC b cdot 10^{-3}$ \NC c $10 \NC d cdot 10^3$ \NR\NC 1 \NC 2 \TWO \NC 4 \NRHL
\stoptabulate
 
\stoptext
</texcode>
|
|<context>
\def\tabulateuse#1%
{\dorecurse{\numexpr2*#1-1\relax}{\span\omit}}
\appendtoks \let\use\tabulateuse \defineTABLEshorthands\to \everytabulatealthough both variants do work.
\starttextIf you always need math in one column, consider math mode columns:
<texcode>\starttabulate[|lm|Br|l|lm|]\NC a HL\NC b 10e-3 \NC c \NC d 10e+3 \NR\NC 1 \NC 2 \TWO \NC 4 \NRHL
\stoptabulate
</texcode>
\stoptext
</context>
|}
=Itemization or framed objects inside a tabulation= Paragraph columns == The following issue is related to MkIV:
For spanned columns in cells with paragraphs you need When using an itemization inside a differenttabulation where one uses also the implementation{{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>
To use this macro you have to take care about a few thingsThe following code provided by Wolfgang Schuster demonstrates the problem:Compile with and without the line <tt>\tabulatesplitlinemode\plustwo</tt>
* You have to set a width for each cell<texcode>\tabulatesplitlinemode \plustwo\starttabulate[|p|]\NCone \par\blank[penalty:10000]two \par\blank[penalty:10000]three\NC\NR\stoptabulate</texcode>
* The format for the spanned column same is fixed and true if you have to change use {{cmd|framed}} or something that uses it in the macrointernally, like [[Widgets]], within Tabulate.
{| ! width="45%"| ! widthCombining enumerations and tabulations="10%"| ! width="45%"| |- | <texcode>\def\tabulateuse#1% {\dorecurse{\numexpr2*#1-1\relax}{\span\omit}\raggedright\ignorespaces}
\appendtoks \let\use\tabulateuse \defineTABLEshorthands\to \everytabulate{{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>\starttextstartitemize[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[|p(2cm)|p(3cm)|p(4cm)||]\NI x \NC y \dorecurse{10}{text } NC z \NC \dorecurse{4}{Lorem Ipsum } NR\NI x \NCy \dorecurse{18}{text } NC z \NC\NR\NI x \NC y \TWO Short text spanning two tabulate paragraphs. NC z \NC\NR\dorecurse{17}{text } NI x \NC y \NC z \NC\NR
\stoptabulate
\stopitemize
\stoptextstartitemize[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>
|
|<context>
\def\tabulateuse#1%
{\dorecurse{\numexpr2*#1-1\relax}{\span\omit}\raggedright\ignorespaces}
 
\appendtoks
\let\use\tabulateuse
\defineTABLEshorthands
\to \everytabulate
\starttext\switchtobodyfont[8pt]=EQ option within table=
\starttabulate[|p(2cm)|p(3cm)|p(4cm)|]\NC \dorecurse{10}{EQ option defines text } which will be placed by \NC \dorecurse{4}{Lorem Ipsum } \NCEQ column separator.\dorecurse{18}{text } \NC\NR\NC \TWO Short text spanning two tabulate paragraphsSource: https://www.mail-archive.com/ntg-context@ntg.nl/msg95207. \NC\dorecurse{17}{text } \NC\NR\stoptabulatehtml
<context mode=mkiv source=yes> \stoptextstarttabulate[|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 only in the [[source:{{src|tabl-tbl.mkiv|source]]}}. * [[{{cmd:|starttabulate}}, {{cmd|Command description]]setuptabulate}}
* [[TABLE|Natural Tables]]
 * [[{{cmd:|starttable}}, <s>{{cmd|Table environment]]setuptable}}</s>
[[Category:Tables]]

Navigation menu