Changes

Jump to navigation Jump to search
2,215 bytes added ,  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.
Note that the table is split after the yyy row.
= Tables in multiple columns = Headers with TABLEs ==
... just work When you have a multi-page TABLE in the document (at least in luaTeX using either the <tt>split=repeat</tt> or <tt>split=yes</tt> options), and not here...the (page)header text is also styled with a TABLE, the table header ends up getting crammed into the document header resulting in incorrect output. See To alleviate this, {{cmd|bTABLEnested}} and {{cmd|eTABLEnested}} may be used as in the following examplebelow to ensure that table headers don’t get mixed up with the document header.
<texcode>
\starttext\startcolumnssetupheadertexts[n=3]\bTABLE\dorecursedirectsetup{21headertable}{\bTR \bTD a\eTD \bTD b \eTD \eTR}\eTABLE\stopcolumns\stoptext</texcode>]
\startsetups [headertable]\bTABLEnested[option= Creating tables from CSV data (Comma Separated Values) stretch,frame=off]\setupTABLE[c][1][align=flushleft]\setupTABLE[c][2][align=flushright] \bTR \bTD Firstname Lastname \par 123, First street \par Ph: 1234567890 \par \eTD \bTD Company Name \par 123, First street \par Ph: 9876543210 \par \eTD \eTR\eTABLEnested\stopsetups
See also [[m-database|the database module]]!\starttext
and \bTABLE[http://dl.contextgarden.net/myway/csv.pdf Creating Tables using CSV (Comma-separated values)split=repeat, option=stretch] by Mojca Miklavec\bTABLEhead \bTR[style=bold]\dorecurse{5}{\bTH Header Col #1\eTH}\eTR\eTABLEhead\bTABLEbody \dorecurse{50}{\bTR\dorecurse{5}{\bTD Row #1 col ##1\eTD}\eTR}\eTABLEbody\eTABLE
 <!-- 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}stoptext
</texcode>
The next lines are an example Compiling the above by using {{cmd|bTABLE}} and {{cmd|eTABLE}} instead of transforming {{cmd|bTABLEnested}} and {{cmd|eTABLEnested}} in the setup for <tt>headertable</tt> one notices the data into a natural table, but can be easily adapted to any need for the nested 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}= Tables in multiple columns =
\def\dostartCSV#1\stopCSV{% \bTABLE \ProcessLines\TBLline{#1}% \eTABLE \egroup}</texcode> The ... should just work (at least in your installation but not here...). See the following lines will then finally result in a desired table:example.
<texcode>
% some additional settings for the table may be made as well\setupTABLEstartcolumns[cn=3][2][style=\tt]bTABLE\setupTABLE[c][3][align=middle]dorecurse{21}{\bTR \bTD a\eTD \setupTABLE[r][1][style=bold] % how to override the bTD b \tt in the second column? eTD \startCSVName,Email,AcceptedeTR}\CONTEXT,worth@trying.to,YesHans,main@developer.of,YesBug,get@rid.of,NoeTABLE\stopCSVstopcolumns
</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
\eTABLE
</context>
 
== Cells with breaking lines ==
 
If you provide a width to a cell the lines will break.
 
<context source="yes" text="produces">
\setupTABLE[c][2][width=3cm]
\bTABLE
\bTR \bTD 1 \eTD \bTD This is a very long line that should break. \eTD \eTR
\eTABLE
</context>
 
== Rules ==
</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 ===
</context>
 
= Settings for multiple TABLEs in a single page =
 
Please note that if you have multiple TABLEs in a single page, use the \start & \stop commands to ensure the locality of the attributes of each table. Else settings from one TABLE might have strange effects on the settings of another.
 
When you need a certain setup for multiple tables you can put all \setupTABLE commands in a setups-environment and load these settings at the start of the table, e.g.
 
<texcode>
\startsetups [tablesettings]
\setupTABLE [r] [1] [..,..=..,..]
\setupTABLE [c] [2] [..,..=..,..]
\stopsetups
 
\bTABLE[setups=tablesettings]
...
\eTABLE
</texcode>
 
When you need individual settings for each table add \start before the setup-commands and \stop after the table, this keeps all setups local to the current table, e.g.
 
<texcode>
\start
 
\setupTABLE [r] [1] [..,..=..,..]
\setupTABLE [c] [2] [..,..=..,..]
 
\bTABLE
...
\eTABLE
 
\stop
</texcode>
 
= Creating tables from CSV data (Comma Separated Values) =
 
'''Beware, this is very old code'''; while it might still work (untested), it makes more sense to do 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>
% 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}}.

Navigation menu