14

I'm trying to have an overlay that adds a background color to a column of a table in beamer.

I can create a table with a colored second column using the colortbl package.

\begin{tabular}[]{r >{\columncolor{red!30}}} c}
...
\end{tabular}

If I try to simply make the color code an overlay this doesn't work (as I expected).

\begin{tabular}[]{r \onslide[2-]{>{\columncolor{red!30}}} c}

Can I create the effect I intend (without simply duplicating the table)?

ziggystar
  • 706
  • On a side note and just in case someone might have the same question as I had (Google brought me here): I tried to do the same thing with \cellcolor and used \visible<2-> but that didn't work – the cell still had the same color in every frame. The solution: Use \only instead of \visible. – balu Jul 07 '13 at 18:41

3 Answers3

15

Try conditionally defining a column type and using that:

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

\begin{frame}
\alt<2->{\newcolumntype{C}{>{\columncolor{red!30}}c}}{\newcolumntype{C}{c}}
\begin{tabular}[]{rC}
1 & 2 \\
3 & 4 \\
\end{tabular}
\end{frame}
\end{document}
Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
3

You may define a custom column type associated with a custom color then change the definition of your color:

\documentclass{beamer}
\usepackage{colortbl}

\colorlet{mycol}{white}
\newcolumntype{A}{>{\columncolor{mycol}}c}

\begin{document}
\begin{frame}
\only<2>{\colorlet{mycol}{lime}}
\begin{tabular}[]{cA}
1 & 2 \\
3 & 4 \\
\end{tabular}
\end{frame}
\end{document}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
1

Also, have a look at this link (german), very useful for rowcolor https://groups.google.com/forum/?fromgroups#!topic/de.comp.text.tex/v7qQFV3pjkw

Code from the linked discussion:

\documentclass{beamer}
\usepackage{colortbl}
\begin{document}
    \begin{frame}{Test}
        \begin{tabular}{l}
            \only<2>{\\\rowcolor{blue!50}}Test!
        \end{tabular}
    \end{frame}
\end{document}