Difference between revisions of "Table"

From Wiki
Jump to navigation Jump to search
Line 177: Line 177:
 
\stoptable
 
\stoptable
 
</context>
 
</context>
 +
 +
=Examples=
 +
 +
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.
 +
<texcode>
 +
\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
 +
</texcode>

Revision as of 16:02, 21 December 2005

< Tables Overview

This is ConTeXts oldest table module. It uses the same formatting as tabulate. (See Tables Overview for an overview.)

\placetable[here][tab:sample]{sample table}
\starttable[|l|l|]
\HL
\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
\NC \tex{SR}	\NC single row	\NC\FR
\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
\NC \tex{AR}	\NC automatic row	\NC\SR
\HL
\stoptable

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).

If you need information about \placetable look after \placefloat in the manual! If you'd like to leave out the table's caption, you can't simply leave the braces empty but must write none!

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 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 a necessary. The formatting keys for each column can be a choice of

Key Meaning
Primitive keys
a{tokens} Adds tokens after the column content
b{tokens} Adds tokens before the column content
\{ Enclose the column in braces
*{n}{keys} Equivalent to repeating the formatting keys keys n times
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
Numeric item keys
n Numeric item not in math mode
N Numeric item in math mode
Attribute keys
m Each cell is in (inline) math mode. Equivalent to b$ a$
M Each cell is in display math mode. Equivalent to \{b{$\displaystyle}a$
\m Equivalent to l b{{}}m
\M Equivalent to l b{{}}M
f Set font according to following \command
B Bold. Equivalent to f\bf
I Italic. Equivalent to f\it
S Slanted. Equivalent to f\sl
R Roman. Equivalent to f\rm
T Teletype. Equivalent to f\tt
p Set each cell as a paragraph
Minimum column width key
w Set minimum column width
Tabskip keys
s Set the tabskip to the right of this column and of all following columns until the next s or o 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 \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.

The only ConTeXt docs about it are in ms-cb-en.pdf.

The sample looks like this:

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

Examples

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