答案1
下面定义了一个\tableonly
应该在tabular
环境中工作的命令(它对我的小测试文件有效)。
玩得开心。
\documentclass[]{beamer}
\usepackage{array}
\newcolumntype\math[1]{>{\(}#1<{\)}}
\newcounter{iteration}
\makeatletter
\newcommand*\tableonly%>>>
{%
\omit\@ifnextchar<\table@only\table@@only
}%<<<
\protected\long\def\table@only<#1>#2%>>>
{%
\gdef\beamer@doifnotinframe{\cr}%
\def\beamer@doifinframe{\cr#2}%
\beamer@masterdecode{#1}%
\beamer@donow
}%<<<
\protected\long\def\table@@only#1%>>>
{%
\beamer@ifnextcharospec{\table@@@only{#1}}{\cr#1}%
}%<<<
\long\def\table@@@only#1<#2>%>>>
{%
\gdef\beamer@doifnotinframe{\cr}%
\def\beamer@doifinframe{\cr#1}%
\beamer@masterdecode{#2}%
\beamer@donow
}%<<<
\makeatother
\begin{document}
\begin{frame}{table}{example}% >>>
\only<1->
{%
\begin{tabular}[]{|\math{c}||*3{\math{c}|}}
\hline
\multicolumn{1}{|c||}{Iteration} & x & d & s \\
\hline
\hline
\tableonly<2->{0 & 1 & 2 & 3 \\\hline}
\tableonly<3->{1 & 1 & 2 & 3 \\\hline}
\tableonly<4->{2 & 1 & 2 & 3 \\\hline}
\tableonly<5->{3 & 1 & 2 & 3 \\\hline}
\end{tabular}%
}%
\end{frame}% <<<
\end{document}
答案2
以下是我评论的方式:
\documentclass{beamer}
\newsavebox\wholeTabular
\newsavebox\partTabular
\newsavebox\fullPartTabular
\newsavebox\LongerWordBox
\newcommand\readWhole[2]{\savebox\wholeTabular{\vbox{\begin{center}\begin{tabular}{#1}#2\end{tabular}\end{center}}}}
\newcommand\readPart[2]{\savebox\partTabular{\vbox{\begin{center}\begin{tabular}{#1}#2\end{tabular}\end{center}}}\savebox\fullPartTabular{\vbox{\begin{center}\begin{tabular}{#1}#2\end{tabular}\vspace*{\dimexpr\ht\wholeTabular+\dp\wholeTabular-\ht\partTabular-\dp\partTabular}\end{center}}}}
\begin{document}
\begin{frame}{Title}
\readWhole{lll}{%
First & 1-1 & 1-2\\
Second & 2-1 & 2-2\\
Third & 3-1 & 3-2
}
\savebox\LongerWordBox{Second}
\readPart{lll}{%
\parbox[t]{\wd\LongerWordBox}{First\hfill} & 1-1 & 1-2\\}
\only<1>{\usebox\fullPartTabular}
\readPart{lll}{%
First & 1-1 & 1-2\\
Second & 2-1 & 2-2\\}
\only<2>{\usebox\fullPartTabular}
\only<3>{\usebox\wholeTabular}
\end{frame}
\end{document}