I have tables in a beamer presentation, and I would like to highlight table rows sequentially (not necessarily in row order) using overlay specifications. So I would like to be able to write code similar to the following:
\begin{tabular}
\color<1>{red}
Row 1 & Row 1 \\
\color<2>{red}
Row 2 & Row 2
\end{tabular}
with the effect that Row 1 is highlighted in red in the first slide and Row 2 is highlighted in the second slide.
I am using a tabu
environment with dcolumn
type columns. Here are some additional details about the findings I've made so far:
- In another post I found code to define a command
dcolcolor
to be able to colourdcolumn
text. - In order to colour the whole row's text without specifying each cell individually, I use
\rowfont
fromtabu
. - In order to make
\rowfont{\dcolcolor{...}}
overlay specification-aware, I try to follow the directions in section 9.6.1 of the beamer user guide.
However, I could not get it to work. So I tried using only
on \rowfont{...}
without trying to define a new, overlay specification-aware command, and I got an error. Here is a MWE:
\documentclass{beamer}
\usepackage{dcolumn}
\usepackage{tabu}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\makeatletter
\def\DC@endright{$\hfil\egroup\@dcolcolor\box\z@\box\tw@\dcolreset}
\def\dcolcolor#1{\gdef\@dcolcolor{\color{#1}}}
\def\dcolreset{\dcolcolor{black}}
\dcolcolor{black}
\makeatother
\begin{document}
\begin{frame}
\begin{tabu}{ld{2}d{2}}
% All of row 1 should be red on all slides
\rowfont{\color{red}\dcolcolor{red}}
Row 1 & 1.234 & 1.234 \
% All of row 2 should be red on second slide only
\only<2>{\rowfont{\color{red}\dcolcolor{red}}}
Row 2 & 2.345 & 2.345 \\
\end{tabu}
\end{frame}
\end{document}
When I compile, I get a couple of errors like
! Misplaced \noalign.
\rowfont ->\ifdim \baselineskip =\z@ \noalign
\fi {\ifnum 0=`}\fi \tabu@row@...
l.28 \end{frame}
The output has two pages. The first page is correct, first row is highlighted (although the first column doesn't appear to be left-aligned). On the second page, the first row is highlighted as expected, but the second row only highlights the numbers, not the first column. Here is a screenshot:
Best Answer