1. To do alternating row colors, you can also include the xcolor package with the table option (i.e. \usepackage[table]{xcolor}), and immediately preceding the tabular environment use the command

\rowcolors{start}{color1}{color2}

— this will produce a table with colored rows, starting at the row indicated by start, with odd rows colored color1 and even rows colored color2.

A bit simpler than putting the rowcolor command before each row.

2. […] 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: […]

3. Terse and to the point. Helps without distracting. Excellent.

• Cool, thanks!! Appreciate it. Best, Tom.

4. Darie

Nice article, thank you very much. It works like a charm 😉

5. Julia Sokol

For some reason using the \rowcolors command seems to do strange things to the table’s border colours. Especially if this table moves to a different part of the page. Very frustraiting.

• Hi Julia,

Could you send a small code example for illustration. I’d be interested to see that and might be able to help…

6. Mallika Thomas

Do you know whether it’s possible to have the highlighting get turned on piecewise in a beamer presentation?

• Hi Mallika,

Either you could repeat the entire table as shown in the code below or use a more sophisticated solution proposed here.

\documentclass{beamer}
\usepackage{colortbl}
\begin{document}

\begin{frame}
\begin{table}
\caption{Table}
\begin{tabular}{ccc}
\hline \hline
First&amp;Second&amp;Third\\\hline%
\only&lt;1&gt;{%
A1&amp;B1&amp;C1\\
\rowcolor{gray}A2&amp;B2&amp;C2\\
A3&amp;B3&amp;C3\\
A4&amp;B4&amp;C4\\[-\normalbaselineskip]
}
\only&lt;2&gt;{%
A1&amp;B1&amp;C1\\
\rowcolor{gray}A2&amp;B2&amp;C2\\
A3&amp;B3&amp;C3\\
\rowcolor{gray}A4&amp;B4&amp;C4\\[-\normalbaselineskip]
}
\\\hline\hline
\end{tabular}
\end{table}
\end{frame}
\end{document}
7. Thanks for this – really helpful. I just wanted to say that \columncolor doesn’t work well with \cline – the colour of the column obscures the line – and that if you wish to colour a table that uses \cline you should switch to \hhline instead.

• tom

Thanks much! Cheers, Tom

8. i can’t do for \cellcolor, can you give me illustration please?

• tom

Hi there,

Thanks for your comment. Here is a simple example:

\documentclass[11pt]{article}
\usepackage{xcolor, colortbl}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{|cc|}
\hline
white&amp;\cellcolor{gray}gray\\
\cellcolor{gray}gray&amp;white\\
\hline
\end{tabular}
\end{table}%
\end{document}

I know there’s an issue with figures and attachement on my blog. Will fix it asap.

Cheers, Tom.

9. Vincent

Hi Tom,

I have been trying to re-do your combination example, but the borders of some columns are misteriously disappearing… Here is my code :

\documentclass[a4paper]{report}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{color, colortbl}
\definecolor{BlueTable}{rgb}{0.30,0.58,0.93}

\begin{document}
\begin{table}[H]
\centering
\newcolumntype{b}{>{\columncolor{BlueTable}}c}
\begin{tabular}{|c|b|b|b|b|b|b|}
col1 & col2 & col3 & col4 & col5 & col6 & col7 \\
\rowcolor{white}
a & b & c & d & e & f & g \\
0 & 1 & 2 & 3 & 4 & 5 & 6 \\
\rowcolor{white}
9 & 8 & 7 & 6 & 5 & 4 & 3 \\
z & y & x & w & v & u & t \\
\end{tabular}
\end{table}
\end{document}

Some vertical lines are missing and the one to the left is disappearing only for the white rows.
Vincent

• tom

Hi Vincent,

Thanks for the nice code example. Unfortunately, I’m not able to reproduce the issue. I can see all vertical lines. Make sure it’s not just the rendering on your screen by zooming in onto the table.

You may want to try the following line of code. Let me know if the vertical lines still disappear.

\begin{tabular}{|c|*{6}{>{\hspace{-\tabcolsep}\,}b< {\hspace{-\tabcolsep}\,}|}}[\sourcecode] I got the code from here.

Thank you very much. Can you also tell us about a package that colors a figure just like ‘colortbl’ colors table rows.

• tom