Changes

Jump to navigation Jump to search
12,383 bytes added ,  11:54, 21 December 2018
m
Document that [] is required for \starttabulatehead in MkIV. Email by Wolfgang Schuster 2018-11-12.
< [[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 ''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 thefirst column should be right aligned (''real''[[right and left|<tt>flushright</tt>]]) and the second columnleft aligned, the formatting characterscorresponding 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%"|
|-
| <texcode>
\starttabulate[|r|l|llB|]
\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% You can leave out the \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|llB|]
\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% You can leave out the \NC before cg(.) \NC align on a character \NC\NR
\HL
\stoptabulate
|}
* <cmd>HL is </cmd> draws a horizontal linerule,* <cmd>NC is </cmd> marks a new column (or new cell),* <cmd>NN</cmd> marks a new math column/cell (see below),* <cmd>NR is </cmd> starts a new row,* <cmd>NB</cmd> starts a new rowas a block (avoids page breaking inside of a block, to keep some lines together<!--; available since beta of 2011-12-21-->);* <cmd>TB</cmd> (= "Table Blank") adds some vertical space between rows -- see an example bellow,* <cmd>VL</cmd> (instead of <cmd>NC</cmd>) 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:<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= <!--(Solution from the mailing list)--> <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 (showing only source here, since it does not compile on the wiki): <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 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 thisargument may not be visible on the first few pages. Rather, itseems 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>
== Headers and Footers ==
==Titles== A tabulating environment can have an optional name which will berepeated 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 thisto 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}, 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> <!-- - ==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 tablepages instead of the title.There is a separate environment {{cmd|starttabulatehead}} wherethis header row has to be specified in advance of its use in atabulation. In ConTeXt MkIV the command requires an additional [], thus you needto write {{cmd|starttabulatehead}}[] instead. {| ! width="55%"| ! width="10%"| ! width="35%"| |- | <texcode>\setuptabulate[headerssplit=yes,header=repeat] % same for footers 
\starttabulatehead
\HLFL \NC {\bf format char} \NC {\bf meaning } \NC\NRAR \HLLL
\stoptabulatehead
 \starttabulate[|lr|l|] \NC c \NC centered \NC\NRAR \NC l \NC left aligned \NC\NRAR \NC r \NC right aligned \NC\NRAR
\stoptabulate
</texcode>
|
| <context>
\setuppapersize[A5]
 
\setuptabulate[split=yes,header=repeat]
<context>
\setuptabulate[headers=repeat] % same for footers
\starttabulatehead
\HLFL \NC {\bf format char} \NC {\bf meaning } \NC\NRAR \HLLL
\stoptabulatehead
 \starttabulate[|lr|l|] \NC c \NC centered \NC\NRAR \NC l \NC left aligned \NC\NRAR \NC r \NC right aligned \NC\NRAR
\stoptabulate
</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.
== Column Spans =Individualizing the Tabulate Look=
Tabulate has no Hans initially announced support for column spans but you could add this function yourselfvertical lines and colors onthe mailing list.[http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html]
The code to do this depends on the tabulate setting and you have to know whatcontent what column setting you need.==Rules==
=== Single row columns Horizontal Rules===
To span columns in cells with <code>l</code>As already demonstrated above, the <codett>r</code> or <code>c\HL</codett>statement insertsyou could use <code>\span\omit\span\omit\span\omit</code> for each cella hairline after the current line.This particularly useful when demarking header and footer rows orYou could prevent these values you could them in separated parts of a macro and use it withtable that should not be as closely<code>\use{2}</code> or <code>\TWO</code> in associated as the rows between the tabulate environmentrules.
{|
! width="4555%"|
! width="10%"|
! width="4535%"|
|-
| <texcode>
\defstarttabulate[|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\tabulateuse#1%NR {\dorecurse{HL\numexpr2*#1-1stoptabulate</texcode>| <context>\relax}{starttabulate[|r|c|l|] \spanNC test \omit}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>|}
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="border:2px solid #addeff"! style="background:#addeff;" | Type !! Description|-|<tt>\appendtoksHL</tt> || standard horizontal rule;|- |<tt>\letFL</tt> || first rule;|-|<tt>\useML</tt> || mid rule;|-|<tt>\tabulateuseLL</tt> || bottom rule;|- |<tt>\LL</tt> and <tt>\defineTABLEshorthandsTL</tt> || bottom rule;|-|<tt>\BL</tt> || last rule.|} Additionally, there is an option <tt>rulecolor</tt> for{{cmd|setuptabulate}} that allows for those rules to \everytabulatebe tinted.
<texcode>\starttextsetuptabulate[rulecolor=red]
\starttabulate[|lr|Br|lc|l|] \FL \NC first row \NC test \NC test \NC\NR \ML \NC a rows in \NC b test \NC c test \NC d \NR \NC 1 between \NC 2 test \NC test \NC\NR \LL \TWO NC last row \NC 4 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 <cmd>VL</cmd> command serves as a replacement for <cmd>NC</cmd>to mark a cell border wherever a vertical rule may be desired (ifthey are to be desired at all from a typographical point ofview). <texcode>\stoptextstarttabulate[||||] \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>
|
|<context>
\def\tabulateuse#1%
{\dorecurse{\numexpr2*#1-1\relax}{\span\omit}}
\appendtoks==Coloring== \let\use\tabulateuse \defineTABLEshorthandsThe following elements can be colorized: rules, cell backgrounds,\to \everytabulateand, obviously, common text. ===Colorizing Rules=== For ''horizontal rules'' see above.
\starttextFor ''vertical rules'', <cmd>VL</cmd> takes a defined color as anoptional argument.
<texcode>\starttabulate[|lr|Br|lc|l|] \VL test \VL[red] red rule \VL test \VL \NR \NC a VL test \NC b VL[green] green rule \NC c VL test \NC d VL \NR \NC 1 VL test \NC 2 VL[blue] blue rule \TWO VL test \NC 4 VL \NR
\stoptabulate
</texcode>
\stoptext===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</cmd> || color is applied to the background of the text and the remaining space on the right.|-|<cmd>CC</cmd> || color is applied to the background of the text only.|-|<cmd>CM</cmd> || color is applied to the background of the text and the remaining space on both sides.|-|<cmd>CL</cmd> || color is applied to the background of the text and the remaining space on the left.|-|<cmd>CT</contextcmd>|| 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>
\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>
=== Paragraph columns ===Those control sequences, if applied within the table body, canreplace the ordinary <cmd>NC</cmd>, 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>
For spanned columns in cells with paragraphs '''caveat emptor'''! The background coloring does apply only tothe ''first'' row of a paragraph cell. Any other cell will comeout colorless. If you need to color an entire multi-line cell,you will need a different implementationto switch to another[[Tables Overview|tabulation variant]].
To use this macro you have to take care about a few things:===Colorizing Cell Text===''Normal text'' inside cells gets its color via the[[Color|standard coloring commands]], or by the shorter variant described above.
* You have to set a width for each cell<texcode>* The format for the spanned column is fixed and you have to change it in the macro\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 ==
{| <! width="45%"|-- ! width="10%"|There does not seem to be an official interface for ! width="45%"|vertical skips. |-Manually placed <code>\blank</code>s are | <texcodecode>\unskipped</code>on purpose.However, as expected there is a token list<code>\def\tabulateuse#1%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 baseline {\dorecurse{\numexpr2*#1-1\relax}{\span\omit}\raggedright\ignorespaces}distance you can use this code:
<texcode>
\unprotect
\appendtoks
\letblank[halfline]\to \uset_tabl_tabulate_every_after_row\protect</texcode> --> <context mode=mkiv source=yes>\tabulateusestarttabulate \defineTABLEshorthandsNC one \NC two \NC\NR \to 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 \everytabulatestoptabulate</context> =Using math mode=
\starttextIf 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:
<texcode>\starttabulate[|p(2cm)l|p(3cm)|p(4cm)l|]\NC \dorecurse{10}{text } \NC \dorecurse{4}{Lorem Ipsum } \NCHL\dorecurse{18}{text } NN 10e-3 \NCNN 10e+3 \NR\NC \TWO Short text spanning two tabulate paragraphs. \NC\dorecurse{17}{text } \NC\NRHL
\stoptabulate
</texcode>
instead of <texcode>\stoptextstarttabulate[|l|l|]\HL\NC $10\cdot 10^{-3}$ \NC $10 \cdot 10^3$ \NR\HL\stoptabulate
</texcode>
|
|<context>
\def\tabulateuse#1%
{\dorecurse{\numexpr2*#1-1\relax}{\span\omit}\raggedright\ignorespaces}
although both variants do work. If you always need math in one column, consider math mode columns: <texcode>\starttabulate[|m|m|]\appendtoksHL \letNC 10e-3 \useNC 10e+3 \tabulateuseNR \defineTABLEshorthandsHL\stoptabulate</texcode>  =Itemization or framed objects inside a tabulation= <!--(added by Willi Egger 04-08-2011, edited by Hraban 2015-10-06)--> The following issue is related to MkIV: 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 \everytabulateplustwo</texcode>
The following code provided by Wolfgang Schuster demonstrates the problem: Compile with and without the line <tt>\starttexttabulatesplitlinemode\switchtobodyfont[8pt]plustwo</tt>
<texcode>\tabulatesplitlinemode \plustwo\starttabulate[|p(2cm)|p(3cm)|p(4cm)|]\NC one \dorecurse{10}{text } \NC \dorecurse{4}{Lorem Ipsum } \NCpar\dorecurse{18}{text } \NC\NRblank[penalty:10000]\NC \TWO Short text spanning two tabulate paragraphs. \NCpar\dorecurse{17}{text } blank[penalty:10000]three\NC\NR
\stoptabulate
</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>\stoptextstartitemize[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>  == More Features =See also=
... * More features are constantly added and documented only in the [[source:{{src|tabl-tbl.mkiimkiv|source}}.* {{cmd|starttabulate}}, {{cmd|setuptabulate}}* [[TABLE|Natural Tables]].* {{cmd|starttable}}, <s>{{cmd|setuptable}}</s>
[[Category:Tables]]
4

edits

Navigation menu