Difference between revisions of "Tabulate"

From ConTeXt wiki
Jump to navigationJump to search
(column span for tabulate)
m (→‎Paragraph columns: Added ConTeXt output)
Line 87: Line 87:
 
* The format for the spanned column is fixed and you have to change it in the macro
 
* The format for the spanned column is fixed and you have to change it in the macro
  
<texcode>
+
{|
 +
! width="45%"|
 +
! width="10%"|
 +
! width="45%"|
 +
|-
 +
| <texcode>
 
\def\tabulateuse#1%
 
\def\tabulateuse#1%
 
  {\dorecurse{\numexpr2*#1-1\relax}{\span\omit}\raggedright\ignorespaces}
 
  {\dorecurse{\numexpr2*#1-1\relax}{\span\omit}\raggedright\ignorespaces}
Line 98: Line 103:
 
\starttext
 
\starttext
  
\starttabulate[|p(4cm)|p(4cm)|p(6cm)|]
+
\starttabulate[|p(2cm)|p(3cm)|p(4cm)|]
\NC \dorecurse{10}{text } \NC \dorecurse{8}{text } \NC
+
\NC \dorecurse{10}{text } \NC \dorecurse{4}{Lorem Ipsum } \NC
 
\dorecurse{18}{text } \NC\NR
 
\dorecurse{18}{text } \NC\NR
 
\NC \TWO Short text spanning two tabulate paragraphs. \NC
 
\NC \TWO Short text spanning two tabulate paragraphs. \NC
\dorecurse{22}{text } \NC\NR
+
\dorecurse{17}{text } \NC\NR
 
\stoptabulate
 
\stoptabulate
  
 
\stoptext
 
\stoptext
 
</texcode>
 
</texcode>
 +
|
 +
|<context>
 +
\def\tabulateuse#1%
 +
{\dorecurse{\numexpr2*#1-1\relax}{\span\omit}\raggedright\ignorespaces}
 +
 +
\appendtoks
 +
  \let\use\tabulateuse
 +
  \defineTABLEshorthands
 +
\to \everytabulate
 +
 +
\starttext
 +
\switchtobodyfont[8pt]
  
 +
\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
 +
</context>
 +
|}
 
[[Category:Tables]]
 
[[Category:Tables]]

Revision as of 21:29, 3 June 2009

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