Difference between revisions of "Table"

From Wiki
Jump to navigation Jump to search
(more/better structure; reworked keys table as ConTeXt table)
Line 1: Line 1:
< [[Tables Overview]]
+
< [[Tables Overview]] | [[tabulate]] | [[Tables]] >
  
This is ConTeXts oldest table module. It uses the same formatting as [[tabulate]]. (See [[Tables Overview]] for an overview.)
+
This is ConTeXts oldest table module. It uses the same formatting as [[tabulate]] (see [[Tables Overview]]).
  
 +
This mode is based on Michael Wichura's TaBlE package for PlainTeX. The official manual for it is commercial (about 40 USD), see [http://www.pctex.com PCTeX] -- but note that the TaBlE manual only talks about the original syntax, which does not use <cmd>NC</cmd>, <cmd>HL</cmd> cum suis.
 +
 +
The only ConTeXt docs are in [[manual:ms-cb-en.pdf|ConTeXt - an excursion]].
 +
 +
== Basic Commands ==
 +
 +
<table cols="2"><tr valign="top"><td>
 
<texcode>
 
<texcode>
\placetable[here][tab:sample]{sample table}
 
 
\starttable[|l|l|]
 
\starttable[|l|l|]
 
\HL
 
\HL
\NC Command \NC Meaning \NC\SR
+
\NC Command \VL Meaning \SR % or \NC\AR
 
\HL
 
\HL
\NC \tex{NC} \NC next column \NC\FR
+
\NC \tex{NC} \VL next column \AR
\NC \tex{HL} \NC horizontal line \NC\MR
+
\NC \tex{HL} \VL horizontal line \AR
\NC \tex{VL} \NC vertical line \NC\MR
+
\NC \tex{VL} \VL vertical line \AR
\NC \tex{NR} \NC next row \NC\LR
+
\NC \tex{NR} \VL next row \LR
 
\HL
 
\HL
\NC \tex{SR} \NC single row \NC\FR
+
\NC \tex{SR} \VL single row \AR
\NC \tex{FR} \NC first row \NC\MR
+
\NC \tex{FR} \VL first row \AR
\NC \tex{MR} \NC middle row \NC\MR
+
\NC \tex{MR} \VL middle row \AR
\NC \tex{LR} \NC last row \NC\LR
+
\NC \tex{LR} \VL last row \LR % or \NC\AR
 
\HL
 
\HL
\NC \tex{AR} \NC automatic row \NC\SR
+
\NC \tex{AR} \VL automatic row \SR % or \NC\AR
 
\HL
 
\HL
 
\stoptable
 
\stoptable
 
</texcode>
 
</texcode>
 +
</td><td>
 +
<context>
 +
\switchtobodyfont[ss, 8pt]
 +
\starttable[|l|l|]
 +
\HL
 +
\NC Command \VL Meaning \SR % or \NC\AR
 +
\HL
 +
\NC \tex{NC} \VL next column \AR
 +
\NC \tex{HL} \VL horizontal line \AR
 +
\NC \tex{VL} \VL vertical line \AR
 +
\NC \tex{NR} \VL next row \LR
 +
\HL
 +
\NC \tex{SR} \VL single row \AR
 +
\NC \tex{FR} \VL first row \AR
 +
\NC \tex{MR} \VL middle row \AR
 +
\NC \tex{LR} \VL last row \LR % or \NC\AR
 +
\HL
 +
\NC \tex{AR} \VL automatic row \SR % or \NC\AR
 +
\HL
 +
\stoptable
 +
</context>
 +
</tr></table>
  
Better use <cmd>SR</cmd>, <cmd>FR</cmd>, <cmd>MR</cmd>, <cmd>LR</cmd> instead of <cmd>NR</cmd>. You can also use <cmd>AR</cmd> instead of <cmd>SR</cmd>, <cmd>FR</cmd>, <cmd>MR</cmd> and <cmd>LR</cmd> (AR for automatic row).
+
* You get vertical lines (rules), if you use <cmd>VL</cmd> instead of <cmd>NC</cmd>.
 +
* Better use <cmd>SR</cmd>, <cmd>FR</cmd>, <cmd>MR</cmd>, <cmd>LR</cmd> instead of <cmd>NR</cmd>.
 +
* You can also use <cmd>AR</cmd> instead of <cmd>SR</cmd>, <cmd>FR</cmd>, <cmd>MR</cmd> and <cmd>LR</cmd> (AR for automatic row).
 +
* You can leave out the <cmd>NC</cmd> before the "row" command, but not if you use <cmd>AR</cmd> in a last or single row (see example).
 +
* You can influence the table with <cmd>setuptables</cmd>.
 +
* There are also <cmd>BL</cmd> and <cmd>CL</cmd> for colored backgrounds, see below.
  
If you need information about <cmd>placetable</cmd> look after <cmd>placefloat</cmd> in the manual!
+
==Column Definition==
If you'd like to leave out the table's caption, you can't simply leave the braces empty but must write <tt>none</tt>!
 
 
 
This mode is based on Michael Wichura's TaBlE package for PlainTeX. The official manual for it is commercial (about 40 USD), see [http://www.pctex.com PCTeX] -- but note that the TaBlE manual only talks about the original syntax, which does not use <cmd>NC</cmd>, <cmd>HL</cmd> cum suis.
 
  
 
The table is defined by the template enclosed in square brackets after <cmd>starttable</cmd>. The template has the form
 
The table is defined by the template enclosed in square brackets after <cmd>starttable</cmd>. The template has the form
<tt>|keys for the first column|keys for the second column|...|keys for the last column|</tt>. Please note that the each column is surrounded by <tt>|</tt> signs. These are a necessary. The formatting keys for each column can be a choice of
+
<tt>|keys for the first column|keys for the second column|...|keys for the last column|</tt>. Please note that the each column is surrounded by <tt>|</tt> signs. These are necessary. The formatting keys for each column can be a choice of
{|
 
! Key || Meaning
 
|-
 
! colspan="2" | Primitive keys
 
|-
 
|a{<i>tokens</i>} || Adds <i>tokens</i> '''after''' the column content
 
|-
 
|b{<i>tokens</i>} || Adds <i>tokens</i> '''before''' the column content
 
|-
 
|\{ || Enclose the column in braces
 
|-
 
|*{<i>n</i>}{<i>keys</i>} || Equivalent to repeating the formatting keys <i>keys</i> <i>n</i> times
 
|-
 
! colspan="2" | Positioning keys
 
|-
 
|\LeftGlue || Specifies the left glue to be used before the column
 
|-
 
|\RightGlue || Specifies the right glue to be used after the column
 
|-
 
|l || Left-align the column
 
|-
 
|c || Center the column
 
|-
 
|r || Right-align the column
 
|-
 
|k || Insert a kern both left and right of the column
 
|-
 
|i || Add a kern to the left of the column
 
|-
 
|j || Add a kern to the right of the column
 
|-
 
! colspan="2" | Numeric item keys
 
|-
 
|n || Numeric item not in math mode
 
|-
 
|N || Numeric item in math mode
 
|-
 
! colspan="2" | Attribute keys
 
|-
 
|m || Each cell is in (inline) math mode. Equivalent to <tt>b$ a$</tt>
 
|-
 
|M || Each cell is in display math mode. Equivalent to <tt>\{b{$\displaystyle}a$</tt>
 
|-
 
|\m || Equivalent to  <tt>l b{{}}m</tt>
 
|-
 
|\M || Equivalent to  <tt>l b{{}}M</tt>
 
|-
 
|f || Set font according to following <cmd>command</cmd>
 
|-
 
|B || Bold. Equivalent to <tt>f\bf</tt>
 
|-
 
|I || Italic. Equivalent to <tt>f\it</tt>
 
|-
 
|S || Slanted. Equivalent to <tt>f\sl</tt>
 
|-
 
|R || Roman. Equivalent to <tt>f\rm</tt>
 
|-
 
|T || Teletype. Equivalent to <tt>f\tt</tt>
 
|-
 
|p || Set each cell as a paragraph
 
|-
 
! colspan="2" | Minimum column width key
 
|-
 
|w || Set minimum column width
 
|-
 
! colspan="2" | Tabskip keys
 
|-
 
|s || Set the tabskip to the right of this column and of all following columns until the next <tt>s</tt> or <tt>o</tt> key
 
|-
 
|o || Set the tabskip to the right of this column only.
 
|}
 
 
 
 
 
It's possible to create columnspans (i.e. cells that span more than one column) with the command <cmd>use[<i>N</i>]</cmd> where <i>N</i> is the number of columns spanned by the cell. It's often necessary to use <cmd>ReFormat[<i>new keys</i>]</cmd> to reformat this specific cell according to the <i>new keys</i>.
 
 
 
The only ConTeXt docs about it are in [http://www.pragma-ade.com/general/manuals/ms-cb-en.pdf ms-cb-en.pdf].
 
 
 
The sample looks like this:
 
  
 
<context>
 
<context>
\placetable[here][tab:sample]{sample table}
+
\switchtobodyfont[8pt]
\starttable[|l|l|]
+
\HL
 +
\NC \bf Key \VL \bf Meaning \SR
 +
\HL
 +
\NC  \NC Primitive Keys \SR
 +
\HL
 +
\NC  \type{a{tokens}}\VL Adds \type{tokens} {\em after} the column content\AR
 +
\NC  \type{b{tokens}}\VL Adds \type{tokens} '''before''' the column content\AR
 +
\NC  {\tt \backslash\{ } \VL Enclose the column in braces \AR
 +
\NC  \type{*{n}{keys}}\VL Equivalent to repeating the formatting keys \type{keys} \type{n} times\NC\LR
 +
\HL
 +
\NC  \NC Positioning Keys\SR
 +
\HL
 +
\NC  \type{\LeftGlue} \VL Specifies the left glue to be used before the column\AR
 +
\NC  \type{\RightGlue} \VL Specifies the right glue to be used after the column\AR
 +
\NC  \type{l} \VL left-aligned column\AR
 +
\NC  \type{c} \VL centered column\AR
 +
\NC  \type{r} \VL right-aligned column\AR
 +
\NC  \type{p} \VL Set each cell as a paragraph\AR
 +
\NC  \type{w} \VL Set minimum column width\AR
 +
\NC  \type{k} \VL Insert a kern both left and right of the column\AR
 +
\NC  \type{i} \VL Add a kern to the left of the column\AR
 +
\NC  \type{j} \VL Add a kern to the right of the column\LR
 +
\HL
 +
\NC \NC Numeric and Math Item Keys \SR
 +
\HL
 +
\NC  \type{n} \VL Numeric item not in math mode\AR
 +
\NC  \type{N} \VL Numeric item in math mode\AR
 +
\NC  \type{m} \VL Each cell is in (inline) math mode. Equivalent to \type{b$ a$}\AR
 +
\NC  \type{M} \VL Each cell is in display math mode. Equivalent to \type{\{b{$\displaystyle}a$}} \AR
 +
\NC  \type{\m} \VL Equivalent to  \type{l b{{}}m}\AR
 +
\NC  \type{\M} \VL Equivalent to  \type{l b{{}}M}\LR
 
\HL
 
\HL
\NC Command \NC Meaning \NC\SR
+
\NC \NC Style Keys \SR
 
\HL
 
\HL
\NC \tex{NC} \NC next column \NC\FR
+
\NC \type{f\command} \VL Set font according to following \tex{command}\AR
\NC \tex{HL} \NC horizontal line \NC\MR
+
\NC \type{B} \VL Bold. Equivalent to \type{f\bf}\AR
\NC \tex{VL} \NC vertical line \NC\MR
+
\NC \type{I} \VL Italic. Equivalent to \type{f\it}\AR
\NC \tex{NR} \NC next row \NC\LR
+
\NC \type{S} \VL Slanted. Equivalent to \type{f\sl}\AR
 +
\NC \type{R} \VL Roman. Equivalent to \type{f\rm}\AR
 +
\NC \type{T} \VL Teletype. Equivalent to \type{f\tt}\LR
 
\HL
 
\HL
\NC \tex{SR} \NC single row \NC\FR
+
\NC \NC Tabskip Keys \SR
\NC \tex{FR} \NC first row \NC\MR
 
\NC \tex{MR} \NC middle row \NC\MR
 
\NC \tex{LR} \NC last row \NC\LR
 
 
\HL
 
\HL
\NC \tex{AR} \NC automatic row \NC\SR
+
\NC \type{s} \VL Set the tabskip to the right of this column and of all following columns up to the next \type{s} or \type{o} key\AR
 +
\NC \type{o} \VL Set the tabskip to the right of this column only\LR
 
\HL
 
\HL
\stoptable
 
 
</context>
 
</context>
  
A very nice application in table are background colors for rows/cells (a feature that doesn't work in tabulate):
+
==Column Spans==
 +
 
 +
It's possible to create columnspans (i.e. cells that span more than one column) with the command <cmd>use[<i>N</i>]</cmd> where ''N'' is the number of columns spanned by the cell. It's often necessary to use <cmd>ReFormat[<i>new keys</i>]</cmd> to reformat this specific cell according to the ''new keys''.
 +
 
 +
==Table as Floating Object==
 +
 
 +
<texcode>
 +
\placetable[here][tab:sample]{sample table}
 +
\starttable ...
 +
</texcode>
 +
 
 +
* See [[Floating Objects]] in general.
 +
* If you need information about <cmd>placetable</cmd> look after <cmd>placefloat</cmd> in the manual or texshow!
 +
* If you'd like to leave out the table's caption (here: "sample table"), you can't simply leave the braces empty but must write <tt>none</tt>!
 +
 
 +
==Background Colors==
 +
 
 +
A very nice application in table are background colors for rows/cells (a feature that doesn't work in [[tabulate]]):
 
<texcode>
 
<texcode>
 
\setupcolors[state=start]
 
\setupcolors[state=start]
Line 157: Line 155:
 
won't cover the whole cell.
 
won't cover the whole cell.
  
* \BL makes a gray background: the optional argument tells BL how many cells it should color
+
* <cmd>BL</cmd> makes a gray background: the optional argument tells BL how many cells it should color
* \CL makes a colored line
+
* <cmd>CL</cmd> makes a colored line
 
<context>
 
<context>
 
\setupcolors[state=start]
 
\setupcolors[state=start]
Line 178: Line 176:
 
</context>
 
</context>
  
=Examples=
+
==Fit Table Width==
  
Hans posted a solution to the list for fitting a wide table (with paragraphs and vertical lines) to the page width. The key to his solution is the (.45\textwidth) settings when setting each cell as a paragraph.
+
Hans posted a solution to the list for fitting a wide table (with paragraphs and vertical lines) to the page width. The key to his solution is the <code>.45\textwidth</code> settings when setting each cell as a paragraph.
 
<texcode>
 
<texcode>
 
\SetTableToWidth{\textwidth}
 
\SetTableToWidth{\textwidth}

Revision as of 14:50, 19 January 2006

< Tables Overview | tabulate | Tables >

This is ConTeXts oldest table module. It uses the same formatting as tabulate (see Tables Overview).

This mode is based on Michael Wichura's TaBlE package for PlainTeX. The official manual for it is commercial (about 40 USD), see PCTeX -- but note that the TaBlE manual only talks about the original syntax, which does not use \NC, \HL cum suis.

The only ConTeXt docs are in ConTeXt - an excursion.

Basic Commands

\starttable[|l|l|]
\HL
\NC Command	\VL Meaning	\SR % or \NC\AR
\HL
\NC \tex{NC}	\VL next column	\AR
\NC \tex{HL}	\VL horizontal line	\AR
\NC \tex{VL}	\VL vertical line	\AR
\NC \tex{NR}	\VL next row	\LR
\HL
\NC \tex{SR}	\VL single row	\AR
\NC \tex{FR}	\VL first row	\AR
\NC \tex{MR}	\VL middle row	\AR
\NC \tex{LR}	\VL last row \LR % or \NC\AR
\HL
\NC \tex{AR}	\VL automatic row	\SR % or \NC\AR
\HL
\stoptable

  • You get vertical lines (rules), if you use \VL instead of \NC.
  • Better use \SR, \FR, \MR, \LR instead of \NR.
  • You can also use \AR instead of \SR, \FR, \MR and \LR (AR for automatic row).
  • You can leave out the \NC before the "row" command, but not if you use \AR in a last or single row (see example).
  • You can influence the table with \setuptables.
  • There are also \BL and \CL for colored backgrounds, see below.

Column Definition

The table is defined by the template enclosed in square brackets after \starttable. The template has the form |keys for the first column|keys for the second column|...|keys for the last column|. Please note that the each column is surrounded by | signs. These are necessary. The formatting keys for each column can be a choice of

Column Spans

It's possible to create columnspans (i.e. cells that span more than one column) with the command \use[N] where N is the number of columns spanned by the cell. It's often necessary to use \ReFormat[new keys] to reformat this specific cell according to the new keys.

Table as Floating Object

\placetable[here][tab:sample]{sample table}
\starttable ...
  • See Floating Objects in general.
  • If you need information about \placetable look after \placefloat in the manual or texshow!
  • If you'd like to leave out the table's caption (here: "sample table"), you can't simply leave the braces empty but must write none!

Background Colors

A very nice application in table are background colors for rows/cells (a feature that doesn't work in tabulate):

\setupcolors[state=start]
\placetable[here][tab:sample]{sample table}
\starttable[|l|l|]
\HL
\BL[2]\SR
\NC Command	\NC Meaning	\NC\SR
\HL
\NC \tex{NC}	\NC next column	\NC\FR
\NC \tex{HL}	\NC horizontal line	\NC\MR
\NC \tex{VL}	\NC vertical line	\NC\MR
\NC \tex{NR}	\NC next row	\NC\LR
\HL
\CL[green]\SR
\NC \tex{AR}	\NC automatic row	\NC\SR
\HL
\stoptable

The commands work something like this: first, you say what background colour you want for the next row and then you typeset the row. Observe: the line with the colour-command and the row it is supposed to colour should end in the same command (i.e. both \SR, \LR, \FR, ...). If they don't, the background won't cover the whole cell.

  • \BL makes a gray background: the optional argument tells BL how many cells it should color
  • \CL makes a colored line

Fit Table Width

Hans posted a solution to the list for fitting a wide table (with paragraphs and vertical lines) to the page width. The key to his solution is the .45\textwidth settings when setting each cell as a paragraph.

\SetTableToWidth{\textwidth}

\starttable[|p(.45\textwidth)|p(.45\textwidth)|]
\HL
\VL foo foo foo foo foo foo \VL bar bar bar bar bar bar \VL\AR
\HL
\stoptable

\stoptext