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?
Your answers will be much appreciated.
Best Answer
As you are already using
xcolor
, instead of loadingcolortbl
, passtable
option toxcolor
. It in turn will loadcolortbl
. To avoid theoption clash
I have added the optiontable
to beamer class as the option!{\vrule}
simply adds a vertical rule. But to use!
you should loadarray
package. You can use|
also instead. The advantage of\vrule
over|
is that you can vary the thickness of the rule.