Background
I would like to "alert
" each row of a table, one row at a time, using Beamer overlays. Using Martin Scharrer's answer to Why can't I wrap \rowcolor in \only? (Beamer), I came up with the following code:
\documentclass{beamer}
\usepackage{tabu}
\makeatletter
\newcommand{\rowonly}{%
\noalign{\ifnum0=`}\fi
\@rowonly
}
\newcommand<>{\@rowonly}[1]{%
\only#2%
{\ifnum0=`{\fi}#1{\ifnum0=`}\fi}%
\ifnum0=`{\fi}%
\ignorespaces
}
\makeatother
\newcommand*{\alertrow}{\rowonly{\rowfont{\color{red}}}}
\begin{document}
\begin{frame}{}
\onslide<+->
\begin{tabu}{ll}
\rowfont{\itshape\color{structure}}
Fruit & Price \\
\alertrow<+> Apples & \$1 \\
\alertrow<+> Bananas & \$2 \\
\alertrow<+> Cherries & \$3
\end{tabu}
\end{frame}
\end{document}
Eventually I'd like to package this kind of table into a custom environment, say alertedfruitprices
, so that it can be reused cleanly. In this environment, it might be nice to redefine \\
to function just as \\ \alertrow
does above. That is, it might be nice for the following to behave as the above tabu
does.
\begin{frame}{Example}
\onslide<+->
\begin{alertedfruitprices}
\\<+> Apples & \$1
\\<+> Bananas & \$2
\\<+> Cherries & \$3
\end{alertedfruitprices}
\end{frame}
Problem
Unfortunately, I am having trouble getting this to work. Ignoring the alertedfruitprices
environment and sticking to a direct use of tabu
for the moment, I tried to use \let
and \def\\
within the first column's preamble, adapting from the answers to How to redefine the \\ in a tabular environment?.
\documentclass{beamer}
\usepackage{tabu}
\makeatletter
\newcommand{\rowonly}{%
\noalign{\ifnum0=`}\fi
\@rowonly
}
\newcommand<>{\@rowonly}[1]{%
\only#2%
{\ifnum0=`{\fi}#1{\ifnum0=`}\fi}%
\ifnum0=`{\fi}%
\ignorespaces
}
\makeatother
\newcommand*{\alertrow}{\rowonly{\rowfont{\color{red}}}}
\begin{document}
\begin{frame}{Example}
\onslide<+->
\begin{tabu}{>{\let\oldcr\\%
\def\\{\oldcr\alertrow}}
ll}
\rowfont{\itshape\color{structure}}
Fruit & Price
\\<+> Apples & \$1
\\<+> Bananas & \$2
\\<+> Cherries & \$3
\end{tabu}
\end{frame}
\end{document}
For some reason, this code does not appear to properly redefine \\
, as evidenced by no overlays and the printing of <+>
at the beginning of each row:
Question
Can someone please explain why the \def\\
is not in effect within the tabu
?
\\
must go in the last column:\begin{tabu}{l >{\let\oldcr\\\def\\{\oldcr\alertrow}}l}
because table cells form implicit groups.