19

How can I use a table with alternately colored rows like this in a beamer slide? There seems to be a conflict with beamer and xcolor. I am using LyX too, bonus marks for something that works well in LyX.

\documentclass{article}
\usepackage[table]{xcolor}
\begin{document}
\begin{center}
\rowcolors{1}{tableShade}{white}
\rowcolors[]{2}{blue!20}{blue!10}
\begin{tabular}{ r p{4cm} l}\hline
\textbf{col1} &\textbf{col2} &\textbf{col3}\\\hline
& & \\
& & \\
& & \\
& & \\
& & \\
& & \\
\end{tabular}

\end{center}

\end{document}
1
  • 4
    The problem is that that beamer already loads xcolor, but without the table option. LaTeX generates an error if a package is loaded twice with different options. So you have to get the first instance to be loaded with the table option.
    – Caramdir
    Jan 12, 2011 at 4:29

3 Answers 3

24

It's easy:

\documentclass[xcolor=table]{beamer}

or

\documentclass[table]{beamer}

You can also use:

\PassOptionsToPackage{table}{xcolor}
\documentclass{beamer}
3
  • 1
    I think the first option works in Lyx. You need to go to the toolbar and select Document -> Settings -> select "Document Class" from the sidebar -> Go to the "Custom" box in the "Class Options" section -> enter "table"
    – denilw
    Jan 12, 2011 at 4:52
  • 1
    I face the same problem, in LyX, when both LyX' Track Changes function is active as well as the Show changes in output option. Entering the table or xcolor=table option does not help. Neither does the command \PassOptionsToPackage{table}{xcolor}. Any ideas? Jun 22, 2012 at 15:00
  • It works using table as a document class option and, of course, erasing (if any) the \usepackage[table]{xcolor} entry from the Preamble. It does not work using xcolor=table. Jun 23, 2012 at 1:48
4

You can also pass it as follows:

\documentclass[xcolor=table]{beamer}
1
0

I've been using the option xcolor=table of beamer until now, and suddenly it stopped working.

When I code:

\documentclass[xcolor=table]{beamer}
\begin{document}
\rowcolors{1}{red}{green}
\begin{tabular}{ll}
1&2\\
3&4\\
5&6\\
7&8
\end{tabular}
\end{document}

I get the error "\rowcolors undefined".

On the other hand, if I code

\PassOptionsToPackage{table}{xcolor}
\documentclass{beamer}
\begin{document}
\rowcolors{1}{red}{green}
\begin{tabular}{ll}
1&2\\
3&4\\
5&6\\
7&8
\end{tabular}
\end{document}

it works.

I wonder why doing it the first way no longer works.

1
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Feb 18, 2022 at 18:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .