2

My question is, how to implement the following overlay for tables in beamer.

  1. rows are shown one-by-one.
  2. rows are shown in sync with an "itemize" in the same slide.
  3. rows have different background colour.

I used the answer from Cell coloring (highlighting) with in-out effects in a table in beamer to do this, but my first column always has a colour in all rows in all slides!!

Here is a MWE:

\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}%

\rowcolors{2}{blue!30}{blue!10}
\begin{itemize}
\item \visible<1->{Item1}
\item \visible<2->{Item2}
\item \visible<3->{Item3}
\end{itemize}
\begin{center}
\begin{tabular}{cc}
    \visible<1->{Title1 & Title2} \\
    \hline
    \visible<1->{A1 & B1} \\
    \visible<2->{A2 & B2} \\
    \visible<3->{A3 & B3} \\
\end{tabular}
\end{center}
\end{frame}

\end{document}
4

Setting \rowcolors acts globally. You want to just affect each row at a time:

\documentclass[xcolor=table]{beamer}

\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}%

\begin{itemize}
\item \visible<1->{Item1}
\item \visible<2->{Item2}
\item \visible<3->{Item3}
\end{itemize}
\begin{center}
\begin{tabular}{cc}
    \rowcolor<1->{blue!30}\visible<1->{Title1 & Title2} \\
    \hline
    \rowcolor<1->{blue!10}\visible<1->{A1 & B1} \\
    \rowcolor<2->{blue!30}\visible<2->{A2 & B2} \\
    \rowcolor<3->{blue!10}\visible<3->{A3 & B3} \\
\end{tabular}
\end{center}
\end{frame}

\end{document}

Row colouring in beamer

  • You can simplify your itemize environment as there's no need of all those \visible: just use \item<...>. – Claudio Fiandrino Apr 25 '14 at 6:22
  • @ClaudioFiandrino True. I really just wanted to show the minimal changes needed to get the expected results so that this was obvious when compared with the original MWE. But perhaps that is not the best approach... – cfr Apr 25 '14 at 15:32
  • 1
    You can always suggest more convenient alternatives when possible :) – Claudio Fiandrino Apr 25 '14 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.