Tables

Tables without vertical lines (tabulate)

The tabulate environment allows you to create simple tables, suited for tables with large blocks of text. This type of table does not produce vertical lines between cells—hence the name tabulate, hinting at the type of table created with tabs.

Rather than try to explain the many details of this layout, let me first show the code example.

% start envrionment and setup columns
\starttabulate[|p(6cm) j3|p(6cm)|]

% create a cell
\NC American Community Survey 
%
%create a cell
\NC Current Population Survey 
%
% end the row
\NC\NR
% create a horizontal line
%
\HL
%
% create a cell
\NC 
All dollar values for income are adjusted 
to latest calendar year of estimates using 
the Consumer Price Index for the date collected 
versus the average for the year.
% create a cell
\NC None
%
% end the row
\NC\NR
%
% end tabulate
\stoptabulate

source file

Setting up the columns

Begin the table with the starttabulate command. Set up the column information in the first option. The information for formatting each column gets put between the “|” character. A one column table needs 2 “|” characters, a two column table needs 3 “|” characters, and so on.

The first colum of my table has two commands. The first, p(6cm), tells ConTeXt to create a 6 cm paragraph for the column. If the column contains cells with brief text that aren’t really paragraphs, use the l, r, or c property. The l command aligns the text left; the r aligns the text right; and the c command centers the text. For example, for a two-column table, my setups might look like this:

% make two columns, both aligned left
\starttabulate[|l|l|]

In addtion, one can use the w property for a one line column. Like the p option, the [:pr; w] option takes a dimmension in parenthesis.

Each column must contain one of the above properties, so that ConTeXt knows how to format it.

The setups for each column can have additional commands. The j3 option in my table creates space after the column. A number lower than 3 creates less space, while a number greater than 3 creates more. The opposite property, i creates space before the column, and functions just like its counterpart j. The property k seems to create space on either side of the column.

Here is a summary of the options for the column setups.

option result
Formatting Characters for Tables
l align left
r align right
c align center
p(dimen) create a paragraph with width dimen
w(dimen) create a column with width dimen
f #1 font
B bold
I italic
S slanted
T Type
R roman
m math
M display math
h hook (inner level of par lines)
b before (may be command)
a after (may be command)
i<number> skip left of column
j<number> skip right of column
k<number> skip around column

Body commands

Within the body of the table itself, issue comand in order to create cells, rows, and horiziontal lines. The NC command creates a new cell. The NR command creates a new row. The HL creates a horizontal line.

You must end every rown (including the last) with the NR command.

Standard table

The standard table commands give us pretty good flexibility in creating complicated tables.

Basic Table

Here is a basic table.

\placetable[here][tab:insurance]{Percentage of People without health
insurance in US}
\starttable[|l w(30mm)|l|l|]
\HL
\VL State     \VL 3-year average \VL 2-year average \VL\SR
\HL[4]
\VL Alabama   \VL 13.3           \VL 13.5           \VL\FR
\HL
\VL Alaska    \VL 17.8           \VL 18.8            \VL\MR
\HL
\VL Arizona   \VL 17.3            \VL 16.9           \VL\LR
\HL
\stoptable

source file

Merging cells vertically

In order to merge cells vertically, don’t use the HR command to draw a continuous line. Instead, use a combination of the DL, DC and DR commands to draw lines under the columns you want.

* The DL command draws a line under the next column, and then skips a column. This last part is important to remember. If you start your line-drawing commands with a DL command, ConTeXt draws a line under column one and then leaves a blank for column two. In essence, the DL command issues two commands: (1) draw a line across the column(s); and (2) create an empty space across the following column.

If you want to draw a line across two columns, use an option after the DL command, and make the option the number of how lines you wish to draw.

% draw a line across two columns, then down't draw a line across the
% next
\DL[2] ...

Note the difference between the first and second command below. The first leaves no line under the middle column. The second command leaves no line under the third column.

% draws a line for column one, skips column two, and draws a line 
% for column three
\DL \DL ...
% draws a line for columns one and two, and skips column three
\DL[2] ...

* The DC command tells ConTeXt to draw no line.

% skips column one before drawing a line for column two
% and leaving the a blank for column 3
\DC \DL ...

* The DR command is used to end a row which contains DL or DC command.

% draws a line for column one, skips column two, and draws a line 
% for column three
% (same as above, except now the rows are properly ended)
\DL \DL \DR
% draws a line for columns one and two, and skips column three
\DL[2] \DR

source file

Tables with TABLE

The TABLE is the most powerful and flexible tables module in ConTeXt. Its sytax is closest to css stylesheets.

You can find a PDF file with many examples at url=http://www.pragma-ade.com/general/manuals/enattab.pdf

The following is a simple table.

\bTABLE
\bTR \bTD State \eTD \bTD3-year average \eTD \bTD2-year average \eTD \eTR
\bTR \bTD Alabama \eTD \bTD 13.3 \eTD \bTD 13.5 \eTD \eTR
...
\eTABLE

source file

Each command in the TABLE environment is paired: bTABLE is matched with eTable, bTR is matched with eTR, and so on. The lower-case “b” stands for beginn, while the lower-case “e” stands for end.

The commands otherwise look very much like XHTML format, with TR standing for table row, and TD for table cell.

Merging cells horizontally

In order to merge cells horiziontally, use the nc option after the cell you want to merge. The nc stands for number of columns.

\bTABLE
\bTR \bTD State \eTD \bTD3-year average \eTD \bTD2-year average \eTD \eTR
%
% merge the first two cells
\bTR \bTD[nc=2] Alabama \eTD  \bTD 13.5 \eTD \eTR
%
% merge last two cells
\bTR \bTD Alaska \eTD \bTD[nc=2] 17.8 \eTD  \eTR
%
%merget all three cells
\bTR \bTD[nc=3] Arizona \eTD  \eTR
\eTABLE

source file

Merging cells vertically

In order to merge cells vertically, use the nr option after the cell you want to merge. The nj stands for number of rows.

\bTABLE
\bTR \bTD State \eTD \bTD3-year average \eTD \bTD2-year average \eTD \eTR
%
% merge first cell down one
\bTR \bTD[nr=2] Alabama \eTD \bTD 13.3 \eTD \bTD 13.5 \eTD \eTR
%
% merge last cell down one
\bTR \bTD 17.8 \eTD \bTD[nr=2] 18.8 \eTD \eTR
\bTR \bTD Arizona \eTD \bTD 17.3 \eTD  \eTR
\eTABLE

source file

Creating multi-page tables

In order to make sure a larget TABLE can split across pages, use the option split=yes right after the bTABLE command.

\bTABLE[split=yes]

If you want create tables in which the header is repeated with each page, divide your table into the head, body, and foot. Use the bTABLEhead and eTABLEhead to create the head. Use the bTABLEbody and eTABLEbody to create the body. Use the bTABLEfoot and eTABLEfoot to create the foot.

Use the option split=repeat right after the bTABLE command.

The head will appear at the top of the table on each page. The foot will appear once at the bottom of the table.

% split the table across pages and make sure the head is foot are repeated
\bTABLE[split=repeat]
% create the head
\bTABLEhead
\bTR \bTD State  \eTD \bTD 3-year average \eTD \bTD 2-year average \eTD \eTR
\eTABLEhead
% create the body
\bTABLEbody
\bTR \bTD Alabama  \eTD \bTD 13.3  \eTD \bTD 13.5  \eTD \eTR
\bTR \bTD Alaska  \eTD \bTD 17.8  \eTD \bTD 18.8  \eTD \eTR
...
\eTABLEbody
% create the foot
\bTABLEfoot
\bTR \bTD[nc=3] Details may not sum to totals because of rounding. \eTD \eTR
\eTABLEfoot
\eTABLE

source file

Customizing TABLE

Customizing cells and rows in TABLE is more straightforward than with other table modules. Use the setupTABLE command. The first few commands of this option describe the rows, columns, or cells that need to be customized. The last option describes the actual customization.

You can use as many setupTABLE commands as you have customizations.

copyright 2005 Paul Henry Tremblay

License: GPL

home | contents | previous | next

SourceForge.net Logo

last updated: 2005-04-11