Beamer \only 命令弄乱了表格

Beamer \only 命令弄乱了表格

在 beamer 中,我尝试创建一组逐行的幻灯片表格:每张幻灯片显示一个新行。我解决了很多问题,但仍然遇到生成额外部分行的问题。(见图)如果我注释掉不可见的行,则不会生成额外的行。但当然,我失去了我想要的逐行显示。

有什么想法吗?

在此处输入图片描述

答案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}

在此处输入图片描述

相关内容