Changes

Jump to navigation Jump to search
6,541 bytes added ,  20:50, 15 May 2022
=Introduction=
This table mode The preferred way to typeset tables is to use what are called &ldquo;natural tables&rdquo; or (also known as &ldquo;automatic tables.&rdquo; I'd call it or &ldquo;HTML tables,&rdquo; because it's very similar to them). They're are especially suited for [[XML]] conversions. Beware: every element must use <tt>\b</tt> ... <tt>\e</tt>! You find a lot of samples in See the [[manual:enattab.pdf|enattab.pdf]] Willi Egger wrote a [[My Way]] how he set a typesetter's lead type case: [http://dl.contextgarden.net/myway/NaturalTablesmanual for many examples.pdf Use of natural tables]
To place a table use:
</texcode>
Here is a A more elaborate example:
<context source=yes>
</context>
Note that every element must use <tt>\b</tt> ... <tt>\e</tt>.
 
Willi Egger wrote a [[This Way - My Way#MyWay|My Way]] how he set a typesetter's lead type case: [http://dl.contextgarden.net/myway/NaturalTables.pdf Use of natural tables]
= Multipage TABLEs =
\stoptext
</texcode>
 
== Changing split location ==
 
Sometimes in multipage tables you have cells that have to stay together:
 
<texcode>
\bTABLE[split=yes]
\dorecurse{10}{\bTR \bTD xxx \eTD \eTR}
\bTR[after=\page] \bTD yyy \eTD \eTR
\dorecurse{10}{\bTR \bTD xxx \eTD \eTR}
\eTABLE
</texcode>
 
Note that the table is split after the yyy row.
 
== Headers with TABLEs ==
 
When one has a multi-page TABLE in the document (using either the <tt>split=repeat</tt> or <tt>split=yes</tt> options), and the header text is also organized as 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 get mixed up with the document header.
 
<texcode>
\setupheadertexts[\directsetup{headertable}]
 
\startsetups [headertable]
\bTABLEnested[option=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
 
\starttext
 
\bTABLE[split=repeat, option=stretch]
\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
 
\stoptext
</texcode>
 
Compiling the above by using {{cmd|bTABLE}} and {{cmd|eTABLE}} instead of {{cmd|bTABLEnested}} and {{cmd|eTABLEnested}} in the setup for <tt>headertable</tt> one notices the need for the nested type.
= Tables in multiple columns =
= Creating tables from CSV data (Comma Separated Values) =
See also [[mM-database|the database module]]!
and [http://dl.contextgarden.net/myway/csv.pdf Creating Tables using CSV (Comma-separated values)] by Mojca Miklavec
From the mailing list at 2005-11-09 by Vit Zyka, modified by Hans Hagen:
<texcodecontext source="yes">\starttextsetuppapersize[A5]
% distance mechanism, per column (H)
\eTABLE
}
</context>
 
== Row Offset/Gap ==
 
Rows, just like columns, can be drawn with a gap.
As above, this can be achieved using:
<texcode>
\bTABLE[spaceinbetween=2cm]
...
\eTABLE
</texcode>
 
A gap differs from an offset as can be seen when drawing
cells using a background and/or a frame.
 
Note that offsets can be uniform <tt>[offset=dimension]</tt>,
or asymmetric
<tt>[toffset=dimension,boffset=dimension,loffset=dimension,roffset=dimension]</tt>
 
=== Gaps for individual cells ===
 
One might want to produce gaps between specific rows and/or specific columns.
This can be achieved using a white frame, for example,
as shown in the following (incomplete) fragment:
<texcode>\stoptextbTABLE[frame=off,columndistance=.5em] ... \bTR[topframe=on,framecolor=white,rulethickness=.5em] ... \eTR ...\eTABLE
</texcode>
 
Note that the <tt>rulethickness</tt> was set for the particular row
and not for the entire table; otherwise, it would enter into the
calculation of the cell dimensions (and interplay with other parameters
such as <tt>columndistance</tt>).
 
More complicated situations, for example, mixing frames, colored cell backgrounds, special gaps, ..., can be achieved using MetaPost graphics as a <tt>background</tt>.
== Make a cell bold ==
\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 ==
[[Category:XML]]
tt>\bTD
 
= An alignment issue =
 
In some cases the alignment of cell contents may not behave as you might expect. Here is an illustrative example. The following code
 
<context source=yes mode=mkiv text="gives us:">
\define[3]\Glyphbox
{\framed[frame=on,align=middle]\bgroup
#1\\
#2\\
#3%
\egroup}
 
\starttext
\setupTABLE[frame=on,align=middle]
\bTABLE
\bTR \bTD \Glyphbox{I}{a}{1} \eTD
\bTD \Glyphbox{I}{a}{1} \eTD
\eTR
\bTR \bTD \Glyphbox{III}{aaa}{111} \eTD
\bTD \Glyphbox{III}{aaa}{111} \eTD
\eTR
\eTABLE
\stoptext
</context>
 
Note that in the first row the cells are not middle-aligned. As Wolfgang Schuster pointed out on the list, we need *two* things to fix this:
 
1. You need <tt>\dontleavehmode</tt> in front of the <tt>\framed</tt>.
2. You need <tt>\setupTABLE[start][..,..=..,..]</tt> because <tt>\bTABLE</tt> sets a default value for the align key which can’t be overwritten with a simple <tt>\setupTABLE[..,..=..,..]</tt>.
 
Implementing this <context source=yes mode=mkiv text="we now get the following correct output with centered cells in the first row:">
\define[3]\Glyphbox
{\dontleavehmode
\framed[frame=on,align=middle]\bgroup
#1\\
#2\\
#3%
\egroup}
 
\starttext
\setupTABLE[start][frame=on,align=middle]
\bTABLE
\bTR \bTD \Glyphbox{I}{a}{1} \eTD
\bTD \Glyphbox{I}{a}{1} \eTD
\eTR
\bTR \bTD \Glyphbox{III}{aaa}{111} \eTD
\bTD \Glyphbox{III}{aaa}{111} \eTD
\eTR
\eTABLE
\stoptext
</context>
 
= Footnotes in TABLEs =
 
From this conversation on the mailing list[https://mailman.ntg.nl/pipermail/ntg-context/2017/089097.html]. In order to get global footnotes printing after tables (without using the local footnotes trick):
 
<texcode>
Text\footnote{Normal Footnote}
\bTABLE[split=repeat,align=normal]
\bTR\bTD Something\postponenotes\footnote[x]{bla bla}\eTD\eTR
\bTR\bTD Foo\note[x] \eTD\eTR
\eTABLE
\flushnotes
More Text\footnote{Another Normal Footnote}
</texcode>
<context mode=mkiv source=no>
\setupnote[footnote][location=text]
\setupnotations[alternative=serried]
\starttext
Text\footnote{Normal Footnote}
\bTABLE[split=repeat,align=normal]
\bTR\bTD Something\postponenotes\footnote[x]{bla bla}\eTD\eTR
\bTR\bTD Foo\note[x] \eTD\eTR
\eTABLE
\flushnotes
More Text\footnote{Another Normal Footnote}
Note that the context wiki is eating the footnote numbers, but that they are there anyways.
\placefootnotes
\stoptext
 
 
</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>
93

edits

Navigation menu