Difference between revisions of "Table"

From Wiki
Jump to navigation Jump to search
(more/better structure; reworked keys table as ConTeXt table)
(fixed column keys table, enhanced layout, added Category:Tables)
Line 64: Line 64:
 
<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
 
<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
  
 +
<table width="100%" cols="2"><tr valign="top"><td>
 
<context>
 
<context>
\switchtobodyfont[8pt]
+
\switchtobodyfont[ss, 8pt]
 +
\starttable[|l|lp(.5\textwidth)|]
 
\HL
 
\HL
 
\NC \bf Key \VL \bf Meaning \SR
 
\NC \bf Key \VL \bf Meaning \SR
Line 83: Line 85:
 
\NC  \type{c} \VL centered column\AR
 
\NC  \type{c} \VL centered column\AR
 
\NC  \type{r} \VL right-aligned column\AR
 
\NC  \type{r} \VL right-aligned column\AR
\NC  \type{p} \VL Set each cell as a paragraph\AR
+
\NC  \type{p(width)} \VL Set each cell as a paragraph\AR
 
\NC  \type{w} \VL Set minimum column width\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{k} \VL Insert a kern both left and right of the column\AR
Line 112: Line 114:
 
\NC  \type{o} \VL Set the tabskip to the right of this column only\LR
 
\NC  \type{o} \VL Set the tabskip to the right of this column only\LR
 
\HL
 
\HL
 +
\stoptable
 
</context>
 
</context>
 +
</td><td>
 +
===Examples===
 +
; <code>|l|</code> : a left aligned column, as wide as necessary
 +
; <code>|lw(2cm)|</code> : a left aligned column of at least 2 cm width
 +
; <code>|p(2cm)|</code> : a centered(!) paragraph of 2 cm width
 +
; <code>|lp(.5\textwidth)|</code> : a left aligned paragraph of specified width
 +
; <code>...</code> : Please add more
 +
; <code>...</code> :
 +
 +
{{todo|add more examples of column definitions}}
 +
</tr></table>
  
 
==Column Spans==
 
==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''.
 
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''.
 +
 +
{{todo|example for column spans}}
  
 
==Table as Floating Object==
 
==Table as Floating Object==
Line 132: Line 148:
  
 
A very nice application in table are background colors for rows/cells (a feature that doesn't work in [[tabulate]]):
 
A very nice application in table are background colors for rows/cells (a feature that doesn't work in [[tabulate]]):
 +
 +
<table cols="2"><tr valign="top"><td>
 
<texcode>
 
<texcode>
 
\setupcolors[state=start]
 
\setupcolors[state=start]
\placetable[here][tab:sample]{sample table}
 
 
\starttable[|l|l|]
 
\starttable[|l|l|]
 
\HL
 
\HL
 
\BL[2]\SR
 
\BL[2]\SR
\NC Command \NC Meaning \NC\SR
+
\NC Command \NC Meaning \SR
 
\HL
 
\HL
\NC \tex{NC} \NC next column \NC\FR
+
\NC \tex{NC} \NC next column \FR
\NC \tex{HL} \NC horizontal line \NC\MR
+
\NC \tex{NR} \NC next row \LR
\NC \tex{VL} \NC vertical line \NC\MR
 
\NC \tex{NR} \NC next row \NC\LR
 
 
\HL
 
\HL
 
\CL[green]\SR
 
\CL[green]\SR
\NC \tex{AR} \NC automatic row \NC\SR
+
\NC \tex{AR} \NC automatic row \SR
 
\HL
 
\HL
 
\stoptable
 
\stoptable
 
</texcode>
 
</texcode>
The commands work something like this:  first, you say what background colour you want for the next row
+
</td><td>
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.
 
 
 
* <cmd>BL</cmd> makes a gray background: the optional argument tells BL how many cells it should color
 
* <cmd>CL</cmd> makes a colored line
 
 
<context>
 
<context>
 
\setupcolors[state=start]
 
\setupcolors[state=start]
\placetable[here][tab:sample]{sample table}
 
 
\starttable[|l|l|]
 
\starttable[|l|l|]
 
\HL
 
\HL
 
\BL[1]\SR
 
\BL[1]\SR
\NC Command \NC Meaning \NC\SR
+
\NC Command \NC Meaning \SR
 
\HL
 
\HL
\NC \tex{NC} \NC next column \NC\FR
+
\NC \tex{NC} \NC next column \FR
\NC \tex{HL} \NC horizontal line \NC\MR
+
\NC \tex{NR} \NC next row \LR
\NC \tex{VL} \NC vertical line \NC\MR
 
\NC \tex{NR} \NC next row \NC\LR
 
 
\HL
 
\HL
 
\CL[green]\SR
 
\CL[green]\SR
\NC \tex{AR} \NC automatic row \NC\SR
+
\NC \tex{AR} \NC automatic row \SR
 
\HL
 
\HL
 
\stoptable
 
\stoptable
 
</context>
 
</context>
 +
</td>
 +
</tr></table>
 +
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.
 +
 +
* <cmd>BL</cmd> makes a gray background: the optional argument tells BL how many cells it should color
 +
* <cmd>CL</cmd> makes a colored line
  
 
==Fit Table Width==
 
==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 <code>.45\textwidth</code> 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}
Line 187: Line 203:
 
\HL
 
\HL
 
\stoptable
 
\stoptable
 +
</texcode>
 +
<!-- It makes no sense to typeset this here. -->
  
\stoptext
+
[[Category:Tables]]
</texcode>
 

Revision as of 15:11, 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

Examples

|l| 
a left aligned column, as wide as necessary
|lw(2cm)| 
a left aligned column of at least 2 cm width
|p(2cm)| 
a centered(!) paragraph of 2 cm width
|lp(.5\textwidth)| 
a left aligned paragraph of specified width
... 
Please add more
... 

TODO: add more examples of column definitions (See: To-Do List)


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.


TODO: example for column spans (See: To-Do List)


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]
\starttable[|l|l|]
\HL
\BL[2]\SR
\NC Command	\NC Meaning	\SR
\HL
\NC \tex{NC}	\NC next column	\FR
\NC \tex{NR}	\NC next row	\LR
\HL
\CL[green]\SR
\NC \tex{AR}	\NC automatic row	\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