Martin's solution is excellent!
Unfortunatelly there is (at least) one situation, where \Temporal
and \Alt
do not behave as one might wish: Using it in an array, one might be interested in an array, where some lines shall be exchanged. \Temporal
produces an error, whereas \temporal
does not.
\documentclass{beamer}
\usepackage{tikz}
\makeatletter
% Detect mode. mathpalette is used to detect the used math style
\renewcommand<>\Temporal[4][l]{%
\begingroup
\ifmmode
\expandafter\mathpalette
\expandafter\math@Temporal
\else
\expandafter\make@Temporal
\fi
{{#2}{#3}{#4}{#1}{#5}}%
\endgroup
}
% Un-brace the second argument (required because \mathpalette reads the three arguments as one
\newcommand\math@Temporal[2]{\math@@Temporal{#1}#2}
% Set the three arguments in boxes. The math style is given by #1. \m@th sets \mathsurround to 0.
\newcommand\math@@Temporal[4]{%
\setbox\z@ \hbox{$\m@th #1{#2}$}%
\setbox\@ne\hbox{$\m@th #1{#3}$}%
\setbox\tw@\hbox{$\m@th #1{#4}$}%
\@Temporal
}
% Un-brace the argument
\newcommand\make@Temporal[1]{\make@@Temporal#1}
% Set the two arguments into normal boxes
\newcommand\make@@Temporal[3]{%
\sbox\z@ {#1}%
\sbox\@ne{#2}%
\sbox\tw@{#3}%
\@Temporal
}
% Place one of the two boxes using \rlap and place a \phantom box with the maximum of the two boxes
\newcommand\@Temporal[2]{%
\setbox\@tempboxa\null
\ht\@tempboxa
\ifnum\ht\z@>\ht\@ne
\ifnum\ht\z@>\ht\tw@
\ht\z@
\else
\ht\tw@
\fi
\else
\ifnum\ht\@ne>\ht\tw@
\ht\@ne
\else
\ht\tw@
\fi
\fi
\dp\@tempboxa
\ifnum\dp\z@>\dp\@ne
\ifnum\dp\z@>\dp\tw@
\dp\z@
\else
\dp\tw@
\fi
\else
\ifnum\dp\@ne>\dp\tw@
\dp\@ne
\else
\dp\tw@
\fi
\fi
\wd\@tempboxa
\ifnum\wd\z@>\wd\@ne
\ifnum\wd\z@>\wd\tw@
\wd\z@
\else
\wd\tw@
\fi
\else
\ifnum\wd\@ne>\wd\tw@
\wd\@ne
\else
\wd\tw@
\fi
\fi
% The \hfil's center the content. Remove one or both of them to right or left align them:
\rlap{\hbox to \wd\@tempboxa{%
\ifx l#1\else\hfil\fi
\temporal#2%
{\box\z@}%
{\box\@ne}%
{\box\tw@}%
\ifx r#1\else\hfil\fi
}}%
\box\@tempboxa
}
\makeatother
\begin{document}
\begin{frame}<1-3>
\[ \left(
\begin{array}{ccc}
\temporal<2>{1 & 2 &3}{1 & 2 & 3\\4 & 5 & 6}{4 & 5 & 6}
\end{array}
\right)
\]
\end{frame}
\begin{frame}<1-3>
\[ \left(
\begin{array}{ccc}
\Temporal<2>{1 & 2 &3}{1 & 2 & 3\\4 & 5 & 6}{4 & 5 & 6}
\end{array}
\right)
\]
\end{frame}
\end{document}
\Alt
macro suitable for math content. – Martin Scharrer♦ Mar 23 '11 at 8:52