Advanced Table Colors

Row Colors

In Section \ref{sec:textcolor} we showed the extended set of colors available through the xcolor.sty package. For tables, it is also useful to have control over the background color of individual rows. One can set row colors via the aptly named \rowcolor macro, and set alternating colors for rows using the \rowcolors macro, starting at a particular row offset. Here is an example:

\colorlet{MyGreen}{green!80!yellow!50}
\colorlet{MyLighterGreen}{green!70!yellow!40}
\rowcolors{3}{MyGreen}{MyLighterGreen}
\begin{tabular}{|c|}
\hline
An Example of Row Colors \\
\hline
Heading can be White \\
\hline
Green \\
Lighter Green \\
Green \\
Lighter Green \\
\hline
\end{tabular}
An Example of Row Colors
Heading can be White
Green
Lighter Green
Green
Lighter Green