Adding color to tables

Texblog had an interesting post on creating tables with alternating colors. See the pdf for the final output. I thought that it will be interesting to see how to reproduce the same effect in ConTeXt. This is the table that I am going to use for my tests:

\NC       \NC Col 1 \NC Col 2 \NC Col 3 \NC Col 4 \NC Col 5 \NC \NR
\NC Row 1 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 2 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 3 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 4 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 5 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR
\NC Row 6 \NC 1     \NC 2     \NC 3     \NC 4     \NC 5     \NC \NR

First lets get the frames right. The example typesets each table with a rules around the first row, a vertical rule after the first column, and a rule after the last column. To get that, use

\startsetups table:frame
\setupTABLE[each][each][frame=off, align=middle, background=color, rulethickness=1bp]
\setupTABLE[row][last] [bottomframe=on]

That is pretty self explanatory. By default, all cells in a table have a frame, so I switch that off with frame=off; each cell should be middle aligned, so I use align=middle; background=color is for later when I will set the color for the table; rulethickness sets the thickness of the line. This setup gives the following result:


Now, lets try the different color setups.

Rows with alternative colors

This one is simple. Set

\startsetups table:rows
\setupTABLE[row][odd] [backgroundcolor=yellow:1]

The colors yellow:1 and blue:1 mean 10% yellow and blue. Then add this setup to the table to get the following result:


Columns with alternative colors

This is almost identical to the row setup.

\startsetups table:columns
\setupTABLE[column][odd] [backgroundcolor=yellow:1]


Chessboard coloring

And now for the most interesting setup: coloring the table cells like a chessboard.

\startsetups table:chessboard
\setupTABLE[odd][odd]  [backgroundcolor=blue:1]



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s