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
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 |
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 |
The standard table commands give us pretty good flexibility in creating complicated tables.
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
The placetable command acts the same way as the placefloat command. The first option, here tells ConTeXt to place the table (if possible) in the current location. The next option is a reference marker. The parameter is the caption of the table. If you don’t want a title but do want the word “table” and number, leave the parameter empty. If you do not want any caption at all, use none for your parameter. If you want a caption but not a number, see the section customizing captions on the figures and float page.
Here is are the source files that create customize captions.
The column setup should look familiar. I setup 3 columns, and made sure the first column was at least 30 mm wide.
Rather than using the NC command to creat a new cell, this table uses VL, which creates a vertical line between each cell.
Notice how the HL command has the option 4. This option increases the line width by a factor of 4. You can use any integer you want—the larger the number, the thicker the width. You can use the same option after a VL command.
The endings for each row are different than the NL commands fromt the tabulate table. Each ending performs a different function.
* The SR command puts extra space between it and the next row. (Frankly, I don’t find this to be the case with my table, but this is what it is supposed to do.)
* The FR command establishes the correct distance for the first row.
* The MR establishes the correct distance for the middle row.
* The LR command establishes the correct distance for the last row.
You can use the AR or automatic row command in place of the SR, FR, and LR commands. The AR command seems to do a good job adjusting the height.
In order to merge cells horizontally, use the NC instead of the VL command, and omit any text for the cell to be merged. In other words, simpley create an empty cell with no border.
\starttable[|l w(30mm)|l|l|] \HL \VL State \VL 3-year average \VL 2-year average \VL\SR \HL[4] \VL Alabama \NC \VL 13.5 \VL\FR ...
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
In order to create a multi-page table with this type of table, follow the example below. I’m not sure of all the details of this type of table, but I have been told it is depreacted, and that for multi-page tables it might be better to use the type of table in the next section. None-the-less, I was able to get this table to work.
% split the table across pages \splitfloat % make sure your group the \placetable with {} {\placetable{Percentage of People without health insurance in US}} % make sure you group everything else with {} % theis table head will repeated on each page {\starttablehead \HL \VL State \VL 3-year average \VL 2-year average \VL\SR \HL[4] \stoptablehead % this detail will be repeated at the bottom of each page \starttabletail \HL[4] \stoptabletail % create a starttables--notice the plural! \starttables[|l w(30mm)|l|l|] \VL Alabama \VL 13.3 \VL 13.5 \VL\FR \HL ... \stoptables}
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
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.
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
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
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
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.
Each cell in the TABLE environment is assigned both a row and column number.
If the table has merged cells, the numbering does not change. The invisible cells are given their number, and the non-invisible cells keep theirs.
Here is a table of possible properties you can use to customize each cell.
option | result | note |
width=<dimen> | set height | |
height=<dimen> | set height | |
background=color | sets color | used in conjuction with color=<color>;use the word "color," not the name of the color |
color=<color> | sets color | used in conjuction with backgroundcolor=color |
frame=<off>|<on> | turns frame (borders) off or on | |
framecolor=<color> | set color of border | |
rulethickness=<dimen> | set thickness of rule for entire frame around cell |
To change something for individual cells using cell addressing (that is, identifying the cells by their rows and numbers), use the [:setupTABLE] command, followed by the number of the column, followed by the number followed by the number of the row, and finally followed by the desired customization. The following table makes the first cell (1, 1) and the middle cell (2, 2) red.
%needed to get color \setupcolors[state=start] % % set up first column, first row \setupTABLE[1][1][background=color, backgroundcolor=red] % % setup second column, second row \setupTABLE[2][2][background=color, backgroundcolor=red]
To change the appearance of one or more rows, use “r” as the property for your first option. In the second option, describe which rows you want to change. Use each for every row; odd for odd rows; even for even rows; first for the first row; last for the last row; a number to indicate a certain row; a series of numbers separated by commas to indicate a series of rows.
% change color of all even rows to red \setupTABLE[r][even][background=color, backgroundcolor=red]
copyright 2005 Paul Henry Tremblay
License: GPL
home | contents | previous | next
last updated: 2005-04-11