# How to uncover alternating row colors in beamer class?

In the howtos section of the beamer documentation (v3.30) I saw the code how to do alternating row colors when displaying tables as a remedy to errors caused by horizontal and vertical lines in tables.
Unfortunately, the code was with errors in my case. I noticed that the \rowcolors macro in the documentation is not mentioned in the colortbl package documentation by David Carlisle on 2012/02/13.

Code as in the beamer class documentation:

\documentclass{beamer}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{graphicx,xcolor}
\begin{document}
\begin{frame}
\rowcolors[]{1}{blue!20}{blue!10} % \rowcolors is not in the colortbl manual
\begin{tabular}{l!{\vrule}cccc} % what's the idea behind !\vrule here, can we avoid it?
Class & A & B & C & D \\\midrule % \midrule instead of the old \hline
X & 1 & 2 & 3 & 4 \pause\\
Y & 3 & 4 & 5 & 6 \pause\\
Z & 5 & 6 & 7 & 8 \\ % double backslash was added as it was not there in the manual
\end{tabular}
\end{frame}
\end{document}


The error thrown:

Undefined control sequence \end{frame}


Questions:
What am I missing here? How to fix this error?
What is the best practice to have alternating colors in beamer class via cleaner lines of code?

• Pass the the table option to the beamer class. – jub0bs Feb 11 '14 at 10:42

As you are already using xcolor, instead of loading colortbl, pass table option to xcolor. It in turn will load colortbl. To avoid the option clash I have added the option table to beamer class as the option

\documentclass[xcolor=table]{beamer}
%\usepackage{xcolor}  %% not needed
\usepackage{booktabs}
%% \usepackage{graphicx}  %% not needed.
\begin{document}
\begin{frame}
\rowcolors[]{1}{blue!20}{blue!10} % \rowcolors is  in the xcolor manual
\begin{tabular}{l|cccc} % \vrule is to Add rule. can use |
Class & A & B & C & D \\\midrule % \midrule instead of the old \hline
X & 1 & 2 & 3 & 4 \pause\\
Y & 3 & 4 & 5 & 6 \pause\\
Z & 5 & 6 & 7 & 8  % double backslash not needed
\end{tabular}
\end{frame}
\end{document}


!{\vrule} simply adds a vertical rule. But to use ! you should load array package. You can use | also instead. The advantage of \vrule over | is that you can vary the thickness of the rule.

• @doctorate Thanks and happy that was useful :) – user11232 Feb 11 '14 at 10:49
• \documentclass[xcolor=table]{beamer} to make it obvious. – user2478 Feb 11 '14 at 10:50