Changes

Jump to navigation Jump to search
1,040 bytes removed ,  07:35, 17 July 2023
m
remove dead mailing list link
Try to divide your table into...
* {{cmd|bTABLEhead}} (table header, can repeat after page breaks)* {{cmd|bTABLEnext}} (alternate table header on following pages)* {{cmd|bTABLEsection}} (subtitle that also can repeat after page breaks)* {{cmd|bTABLEbody}} (table body)* {{cmd|bTABLEfoot}} (table footer)
and {{cmd|setupTABLE}}<tt>[split=yes]</tt> or <tt>[split=repeat]</tt>
is printed only once at the beginning of the table. But if you use <tt>[split=repeat]</tt>,
it is printed on top of every new page, that contains parts of
your multipage table. Please take account of the fact, that thehead cells are enclosed by {{cmd|bTH}} and {{cmd|eTH}} (and not \[be]TCTD).
If you want to use an alternative table header for all following pages,
'''Beware:''' Split tables often begin not on the page (or in the column, if you use them) where they ''could'' start, but on/in the next one.
This is a known limitation due to the complicated calculation of remaining space on the page.
 That won't won’t become better before this calculations are newly written in Lua. (Said Hans on 2010-09-24.)And it became better for LMTX, in 2021/2022.
The following standalone example deals with all the mentioned aspects of natural tables.
== Headers with TABLEs ==
When one has you have a multi-page TABLE in the document (using either the <tt>split=repeat</tt> or <tt>split=yes</tt> options), and the (page) header text is also organized as styled with a TABLE, the table header ends up getting crammed into the document header resulting in incorrect output. To alleviate this , {{cmd|bTABLEnested}} and {{cmd|eTABLEnested}} may be used as in the example below to ensure that table headers don't don’t get mixed up with the document header.
<texcode>
\bTABLE[split=repeat, option=stretch]
\bTABLEhead
\bTR[style=bold]\dorecurse{85}{\bTH Header Col #1\eTH}\eTR
\eTABLEhead
\bTABLEbody
\dorecurse{10050}{\bTR\dorecurse{85}{\bTDRow #1-col ##1\eTD}\eTR}
\eTABLEbody
\eTABLE
\stoptext
 
</texcode>
Compiling the above by using {{cmd|bTABLE}} and {{cmd|eTABLE}} instead of {{cmd|bTABLEnested}} and {{cmd|eTABLEnested}} in the setup for <textt>headertable</textt> one notices the need for the nested type.
= Tables in multiple columns =
... should just work (at least in luaTeX and your installation but not here...). See the following example.
<texcode>
\starttext
\startcolumns[n=3]
\bTABLE
\eTABLE
\stopcolumns
\stoptext
</texcode>
 
= Creating tables from CSV data (Comma Separated Values) =
 
See also [[M-database|the database module]]!
 
and [http://dl.contextgarden.net/myway/csv.pdf Creating Tables using CSV (Comma-separated values)] by Mojca Miklavec
 
 
<!-- Maybe some other place or a separate page is more appropriate for this section -->
 
An interesting example of creating a table using comma separated values was posted to the [http://archive.contextgarden.net/message/20050923.193302.f2110c93.en.html mailing list] by [[User:ChristopherCreutzig|Christopher Creutzig]]
 
The following macros take care of processing CSV data:
<texcode>
% Iterate over all the lines of text captured with \obeylines active
% command to call is first argument, is not called for empty lines
\bgroup
\obeylines
\gdef\ProcessLines#1#2{\doProcessLines{#1}#2^^M\doProcessLines}%
\gdef\doProcessLines#1#2^^M#3\doProcessLines{%
\doifnotempty{#2}{#1{#2}}%
\doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%
}%
\egroup
 
\def\startCSV{\bgroup\obeylines\dostartCSV}
</texcode>
 
The next lines are an example of transforming the data into a natural table, but can be easily adapted to any type of the table or perhaps (mis)used in even more strange ways:
 
<texcode>
\def\TBLentry#1{\bTD#1\eTD}
\def\TBLline#1{\bTR\processcommalist[#1]\TBLentry}
 
\def\dostartCSV#1\stopCSV{%
\bTABLE
\ProcessLines\TBLline{#1}%
\eTABLE
\egroup
}
</texcode>
The following lines will then finally result in a desired table:
 
<texcode>
% some additional settings for the table may be made as well
\setupTABLE[c][2][style=\tt]
\setupTABLE[c][3][align=middle]
\setupTABLE[r][1][style=bold] % how to override the \tt in the second column?
 
\startCSV
Name,Email,Accepted
\CONTEXT,worth@trying.to,Yes
Hans,main@developer.of,Yes
Bug,get@rid.of,No
\stopCSV
</texcode>
 
<context>
\setuppapersize[A5]
 
% Iterate over all the lines of text captured with \obeylines active
% command to call is first argument, is not called for empty lines
\bgroup
\obeylines
\gdef\ProcessLines#1#2{\doProcessLines{#1}#2^^M\doProcessLines}%
\gdef\doProcessLines#1#2^^M#3\doProcessLines{%
\doifnotempty{#2}{#1{#2}}%
\doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%
}%
\egroup
 
\def\startCSV{\bgroup\obeylines\dostartCSV}
 
\def\TBLentry#1{\bTD#1\eTD}
\def\TBLline#1{\bTR\processcommalist[#1]\TBLentry}
 
\def\dostartCSV#1\stopCSV{%
\bTABLE
\ProcessLines\TBLline{#1}%
\eTABLE
\egroup
}
 
\setupTABLE[c][2][style=\tt]
\setupTABLE[c][3][align=middle]
\setupTABLE[r][1][style={\rm\bf}]
\startCSV
Name,Email,Accepted
\CONTEXT,worth@trying.to,Yes
Hans,main@developer.of,Yes
Bug,get@rid.of,No
\stopCSV
</context>
 
Some remarks: the (tentative) code ignores the fact that
* csv data may optionally be enclosed in "" quotes that have to be removed (to be done in \TBLentry)
* quoted strings may contain commas themselves (which means writing a custom version of \processcommalist instead).
 
See also {{cmd|processseparatedlist}}.
= Designing complex TABLEs =
\setupTABLE[r][each][height=0.5cm]
\setupTABLE[c][each][width=1cm]
\setupTABLE[r][1][height=0cm,frame=off]
\bTABLE
\bTR \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \eTR
\bTR \bTD[nc=2,nr=2] r1c1 \eTD \bTD r1c3 \eTD \bTD[nr=2] r1c4 \eTD \bTD[nc=2,nr=2] r1c5 \eTD \eTR
\bTR \bTD[nr=2] r2c3 \eTD \eTR
<texcode>
\setupTABLE[r][each][height=1cm0.5cm]
\setupTABLE[c][each][width=1cm]
\setupTABLE[r][1][height=0cm,frame=off]
\bTABLE
\bTR \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \eTR\bTR \bTD[nc=2,nr=2] r1c1 \eTD \bTD r1c3 \eTD \bTD[nr=2] r1c4 \eTD \bTD[nrnc=2,ncnr=2] r1c5 \eTD \eTR
\bTR \bTD[nr=2] r2c3 \eTD \eTR
\bTR \bTD[nc=2] r3c1 \eTD \bTD[nc=2] r3c4 \eTD \bTD r3c6 \eTD \eTR
\eTABLE
</texcode>
 
N.B. There is an ugly hack in the code. An empty first row with zero height and no borders
is added. If the row is omitted, then something odd happens to the number of
columns. The table should have all cells, so this may be a bug. (Or then I have
blundered something with this example, possibly.)
Everything rectangular can be done with TABLE, as long as it can be fit in the grid. The grid
</context>
See the corresponding thread on the list: [http://www.ntg.nl/pipermail/ntg-context/2011/058549.html rules with different thickness]
=== Thick bottom rules ===
</texcode>
= Tables in page headers Creating tables from CSV data (Comma Separated Values) =
Sometimes you want to use a table layout in a header'''Beware, this is very old code'''; while it might still work (untested), for example it makes more sense to show a company's name and contact information at the top of each page of an invoice. The standard `\bTABLE` command causes issues so use `\bTABLEnested` instead. The parameters are the samedo data processing with Lua.
See also [[M-database|the database module]]!
 
and [http://dl.contextgarden.net/myway/csv.pdf Creating Tables using CSV (Comma-separated values)] by Mojca Miklavec
 
 
<!-- Maybe some other place or a separate page is more appropriate for this section -->
 
An interesting example of creating a table using comma separated values was posted to the [http://archive.contextgarden.net/message/20050923.193302.f2110c93.en.html mailing list] in 2005 by [[User:ChristopherCreutzig|Christopher Creutzig]]
 
The following macros take care of processing CSV data:
<texcode>
% A setup Iterate over all the lines of text captured with \obeylines active% command to define the table's appearancecall is first argument, is not called for empty lines\startsetups headertablebgroup\setupTABLE[frame=off]obeylines\setupTABLE[column][gdef\ProcessLines#1#2{\doProcessLines{#1][align=flushleft]}#2^^M\doProcessLines}%\setupTABLE[column][gdef\doProcessLines#1#2][align=flushright]^^M#3\doProcessLines{% \stopsetupsdoifnotempty{#2}{#1{#2}}%... \doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%}% A setup \egroup \def\startCSV{\bgroup\obeylines\dostartCSV}</texcode> The next lines are an example of transforming the data into a natural table, but can be easily adapted to define any type of the table's contentsor perhaps (mis)used in even more strange ways: <texcode>\startsetups headertextdef\TBLentry#1{\bTD#1\eTD}\bTABLEnesteddef\TBLline#1{\bTR\processcommalist[setups=headertable, ...#1]\TBLentry}...\eTABLEnesteddef\dostartCSV#1\stopCSV{% \stopsetupsbTABLE... \ProcessLines\TBLline{#1}% \eTABLE \egroup}</texcode> The following lines will then finally result in a desired table: <texcode>% Use some additional settings for the table in the headermay be made as well\setupTABLE[c][2][style=\tt]\setupheadertextssetupTABLE[c][3][align=middle]\setups{headertext}setupTABLE[r][1][style=bold]% how to override the \tt in the second column?
\startCSV
Name,Email,Accepted
\CONTEXT,worth@trying.to,Yes
Hans,main@developer.of,Yes
Bug,get@rid.of,No
\stopCSV
</texcode>
 
<context>
\setuppapersize[A5]
 
% Iterate over all the lines of text captured with \obeylines active
% command to call is first argument, is not called for empty lines
\bgroup
\obeylines
\gdef\ProcessLines#1#2{\doProcessLines{#1}#2^^M\doProcessLines}%
\gdef\doProcessLines#1#2^^M#3\doProcessLines{%
\doifnotempty{#2}{#1{#2}}%
\doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%
}%
\egroup
 
\def\startCSV{\bgroup\obeylines\dostartCSV}
 
\def\TBLentry#1{\bTD#1\eTD}
\def\TBLline#1{\bTR\processcommalist[#1]\TBLentry}
 
\def\dostartCSV#1\stopCSV{%
\bTABLE
\ProcessLines\TBLline{#1}%
\eTABLE
\egroup
}
 
\setupTABLE[c][2][style=\tt]
\setupTABLE[c][3][align=middle]
\setupTABLE[r][1][style={\rm\bf}]
\startCSV
Name,Email,Accepted
\CONTEXT,worth@trying.to,Yes
Hans,main@developer.of,Yes
Bug,get@rid.of,No
\stopCSV
</context>
 
Some remarks: the (tentative) code ignores the fact that
* csv data may optionally be enclosed in "" quotes that have to be removed (to be done in \TBLentry)
* quoted strings may contain commas themselves (which means writing a custom version of \processcommalist instead).
 
See also {{cmd|processseparatedlist}}.

Navigation menu