Tabulate

From ConTeXt wiki
Revision as of 10:09, 14 September 2010 by Hraban (talk | contribs) (added headers)
Jump to navigationJump to search

< Tables Overview | Table >

Basic commands

Rather simple tabulating. You need the bars in the formatting field of \starttabulate! If you want vertical lines, you need another table mode (see Tables).

This is especially suited if you want to have paragraphs in one (or more) of the tabulate columns.

The sample describes the formatting characters:

\starttabulate[|l|l|]
\HL
\NC format	\NC meaning	\NC\NR
\HL
\NC c		\NC centered	\NC\NR
\NC l		\NC left aligned	\NC\NR
\NC r		\NC right aligned	\NC\NR
\NC w(1cm)	\NC one line, fixed width	\NC\NR
\NC p(2cm)	\NC paragraph, lines broken to fixed width	\NC\NR
\NC cg(.)	\NC align on a character        \NC\NR
% You can leave out the \NC before \NR
\HL
\stoptabulate
  • HL is horizontal line
  • NC is new column (or new cell)
  • NR is new row

Headers and Footers

\setuptabulate[headers=repeat] % same for footers
\starttabulatehead
\HL
\NC format	\NC meaning	\NC\NR
\HL
\stoptabulatehead
\starttabulate[|l|l|]
\NC c		\NC centered	\NC\NR
\NC l		\NC left aligned	\NC\NR
\NC r		\NC right aligned	\NC\NR
\stoptabulate


Column Spans

Tabulate has no support for column spans but you could add this function yourself.

The code to do this depends on the tabulate setting and you have to know what content what column setting you need.

Single row columns

To span columns in cells with l, r or c you could use \span\omit\span\omit\span\omit for each cell.

You could prevent these values you could them in a macro and use it with \use{2} or \TWO in the tabulate environment.

\def\tabulateuse#1%
  {\dorecurse{\numexpr2*#1-1\relax}{\span\omit}}

\appendtoks
  \let\use\tabulateuse
  \defineTABLEshorthands
\to \everytabulate

\starttext

\starttabulate[|l|Br|l|l|]
\NC a \NC b \NC c \NC d \NR
\NC 1 \NC 2 \TWO  \NC 4 \NR
\stoptabulate

\stoptext

Paragraph columns

For spanned columns in cells with paragraphs you need a different implementation.

To use this macro you have to take care about a few things:

  • You have to set a width for each cell
  • The format for the spanned column is fixed and you have to change it in the macro
\def\tabulateuse#1%
 {\dorecurse{\numexpr2*#1-1\relax}{\span\omit}\raggedright\ignorespaces}

\appendtoks
  \let\use\tabulateuse
  \defineTABLEshorthands
\to \everytabulate

\starttext

\starttabulate[|p(2cm)|p(3cm)|p(4cm)|]
\NC \dorecurse{10}{text } \NC \dorecurse{4}{Lorem Ipsum } \NC
\dorecurse{18}{text } \NC\NR
\NC \TWO Short text spanning two tabulate paragraphs. \NC
\dorecurse{17}{text } \NC\NR
\stoptabulate

\stoptext

More Features

... are documented only in the source.