# 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

\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{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

\begin{document}
\begin{frame}{Example}
\onslide<+->
\begin{tabu}{>{\let\oldcr\\%
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?

-
The redefinition of \\ must go in the last column: \begin{tabu}{l >{\let\oldcr\\\def\\{\oldcr\alertrow}}l} because table cells form implicit groups. –  egreg Sep 3 '12 at 21:11
@egreg Thanks! If you want to convert that to an answer, I'll be happy to accept it. –  Henry DeYoung Sep 3 '12 at 21:16

Every cell in a table is enclosed in a group, so your \def is performed in the first cell of a row and won't be valid in the second one. So do

\begin{tabu}{l >{\let\oldcr\\\def\\{\oldcr\alertrow}}l}


Even better, say

\newcommand{\beamerbackslash}{\let\oldcr\\\def\\{\oldcr\alertrow}}


in the preamble and

\begin{tabu}{l >{\beamerbackslash}l}


in the document body.

-