# Cell overlay in beamer

I used the code posted in this thread to highlight cells in a table:

\documentclass[xcolor=table]{beamer}

\rowcolors{1}{gray!30}{gray!10}

\makeatletter
\def\rowcolor{\noalign{\ifnum0=}\fi\bmr@rowcolor}
\newcommand<>{\bmr@rowcolor}{%
\alt#1%
{\global\let\CT@do@color\CT@@do@color\@ifnextchar[\CT@rowa\CT@rowb}%
{\ifnum0={\fi}\@gooble@rowcolor}%
}

\newcommand{\@gooble@rowcolor}[2][]{\@gooble@rowcolor@}
\newcommand{\@gooble@rowcolor@}[1][]{\@gooble@rowcolor@@}
\newcommand{\@gooble@rowcolor@@}[1][]{\ignorespaces}
\makeatother

\makeatletter
\def\cellcolor{{\ifnum0=}\fi\bmr@cellcolor}
\newcommand<>{\bmr@cellcolor}{%
\alt#1%
{\global\let\CT@do@color\CT@@do@color\@ifnextchar[\CT@rowa\CT@rowb}%
{\ifnum0={\fi}\@gooble@cellcolor}%
}

\newcommand{\@gooble@cellcolor}[2][]{\@gooble@cellcolor@}
\newcommand{\@gooble@cellcolor@}[1][]{\@gooble@cellcolor@@}
\newcommand{\@gooble@cellcolor@@}[1][]{\ignorespaces}
\makeatother

\begin{document}
\begin{frame}{The MWE}%

\only<2>{\rowcolors{1}{blue!30}{blue!10}}
\only<1,3>{\rowcolors{1}{gray!30}{gray!10}}

\begin{center}
\begin{tabular}{cc}
A & B \\
A & B \\
A & B \\
\rowcolor<4>{green} C & D \\
\rowcolor<4,5>{yellow} E & F \\
\rowcolor<4-6>{green} G & H \\
\rowcolor<6>{red} Y & S \\
A & B \\

\end{tabular}
\end{center}

\par
\visible<1>{Testing default row colouring ... \\}
\visible<2,3>{Testing change of default colors ...\\}
\visible<4-6>{Testing in-out of custom colors ...\\ (caution: The order of defaults colors can change)\\}

\vfill
\scriptsize{
Based of answer of Martin Scharrer
\url{https://tex.stackexchange.com/questions/18427/why-cant-i-wrap-rowcolor-in-only-beamer}}

\end{frame}

\begin{frame}{Cell Coloring with In-out Effects}
\begin{center}
\begin{tabular}{cc}
A & B \\
C & \cellcolor<3>{green} C \\
D & E \\
F & G \\

\end{tabular}
\end{center}
\end{frame}

\end{document}


But if I change the last frame to

\begin{frame}{Cell Coloring with In-out Effects}
\begin{center}
\begin{tabular}{cc}
A & B \\
\cellcolor<3>{green} C &  C \\
D & E \\
F & G \\

\end{tabular}
\end{center}
\end{frame}


then the whole second row gets highlighted. Can somebody tell me how to redefine \cellcolor above to make sure that only one cell will be highlighted?

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Jan 17 '15 at 9:55
• It seems that \cellcolor doesn't work as expected. Use \cellcolor<3>{green} C & \cellcolor<3>{gray!10} C as a workaround. Jan 17 '15 at 10:55
• This could surely work, but suppose I had a table with 100 cells and I wanted to do 10 overlays with changing certain cell colors. Then this would be hard to write up. I can't figure out what is wrong in the definition of \cellcolor. Jan 17 '15 at 11:22
• Doesn't it depend on, well, \rowcolor? So it sets it for the whole row or the remainder of the row, depending on where you put the command.
– cfr
Jan 22 '15 at 23:38

A simple redefinition can make \cellcolor overlay-aware:

\documentclass[xcolor=table]{beamer}
\renewcommand<>\cellcolor[1]{\only#2{\beameroriginal\cellcolor{#1}}}

\begin{document}

\begin{frame}

\begin{tabular}{cc}
A & B \\
\cellcolor{green}C &  C \\
D & E \\
\cellcolor<2>{red}F & G \\
\end{tabular}

\end{frame}

\end{document}