[Tex/LaTex] Adding color to a table column as a beamer overlay

beameroverlaystables

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)?

Best Answer

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}