Open main menu

Tabulate

Revision as of 12:50, 16 September 2008 by Wolfgang Schuster (talk | contribs) (column span for tabulate)

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
% 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

The sample looks like this:

 

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(4cm)|p(4cm)|p(6cm)|]
\NC \dorecurse{10}{text } \NC \dorecurse{8}{text } \NC
\dorecurse{18}{text } \NC\NR
\NC \TWO Short text spanning two tabulate paragraphs. \NC
\dorecurse{22}{text } \NC\NR
\stoptabulate

\stoptext