[Tex/LaTex] Beamer alert in Math mode

beamerdcolumnoverlays

I'm trying to alert my audience to numbers in a table that uses the dcolumn alignment environment. \alert works when it's used in a normal table cell, as below.

\documentclass[compress]{beamer}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage[english]{babel}

\begin{document}
\begin{frame}{Table}
\begin{table}\begin{tabular}{l D{.}{.}{3}D{.}{.}{3}}
\toprule
 & \multicolumn{2}{c}{Both}   \\
 \cmidrule{2-3}
{\itshape Variables } & \beta & t\text{-stat} \\ 
\midrule
\multicolumn{3}{l}{{\bfseries 2 Vehicles}}\\ 
\hspace*{1em} $\log($Current Alternative Share$)$ &  -0.417^{***} & -22.1  \\
\hspace*{1em} $\log($Past Alternative Share$)$ &   &  \\
\midrule
$\rho^2_C$  & \multicolumn{2}{c}{\alert<2>{0.0903}} \\
\bottomrule
\end{tabular}
\end{table}
\end{frame}
\end{document}

First
alerted

It does not work, however, when used in the dcolumn cells. The frame below fails with a missing \endgroup inserted error.

\begin{frame}{Table}
\begin{table}\begin{tabular}{l D{.}{.}{3}D{.}{.}{3}}
\toprule
 & \multicolumn{2}{c}{Both}   \\
 \cmidrule{2-3}
{\itshape Variables }& 
 \beta & t\text{-stat} \\ 
\midrule
\multicolumn{3}{l}{{\bfseries 2 Vehicles}}\\ 
%% ALERT CELL %%
\hspace*{1em} $\log($Current Alternative Share$)$ & \alert<3>{-0.417^{***}} & -22.1  \\
%%%%%%%%%%%%%%%%
\hspace*{1em} $\log($Past Alternative Share$)$ &  &  \\
\midrule
$\rho^2_C$  & \multicolumn{2}{c}{\alert<2>{0.0903}} \\
\bottomrule
\end{tabular}\end{table}
\end{frame}

I can alert the text with \text{\alert<n>{x}} but then I lose the alignment and math formatting. \text{\alert<n>{$x$}} doesn't work.

Not working alert

Any tips?

Best Answer

You can define a new column type similar to D that includes the alert specification:

Sample output

\documentclass[compress]{beamer}

\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage[english]{babel}

\makeatletter
\newcolumntype{A}[4]{>{\begin{alertenv}<#4>\DC@{#1}{#2}{#3}}c<{\DC@end\end{alertenv}}}
\makeatother

\begin{document}

\begin{frame}{Table}
\begin{table}\begin{tabular}{l D{.}{.}{3}D{.}{.}{3}}
\toprule
 & \multicolumn{2}{c}{Both}   \\
 \cmidrule{2-3}
{\itshape Variables }& 
 \beta & t\text{-stat} \\ 
\midrule
\multicolumn{3}{l}{{\bfseries 2 Vehicles}}\\ 
%% ALERT CELL %%
\hspace*{1em} $\log($Current Alternative Share$)$ & \multicolumn{1}{A{.}{.}{3}{3}}{-0.417^{***}} & -22.1  \\
%%%%%%%%%%%%%%%%
\hspace*{1em} $\log($Past Alternative Share$)$ &  &  \\
\midrule
$\rho^2_C$  & \multicolumn{2}{c}{{\alert<2>{0.0903}}} \\
\bottomrule
\end{tabular}\end{table}
\end{frame}
\end{document}

These types of constructs are mentioned at the end of the dcolumn documentation.