在 Beamer 中改变数组元素而不移动不变的元素。

在 Beamer 中改变数组元素而不移动不变的元素。

在 Beamer 演示文稿中将显示一个数组,其中某些元素在框架中的所有幻灯片中保持不变。但是,其他数组元素必须随框架中的覆盖层而变化,并且高度和宽度不恒定。似乎最好为每个变量数组条目保留一个不变的空间,其中包含类似于数组本身的内容\overlayarea\overprint但这到目前为止还没有奏效。确实有效的命令\temporal最终会改变幻灯片之间整个数组的位置。

Beamer 中是否有针对此问题的首选和/或优雅的解决方案?

答案1

这里是 的定义和演示代码\Temporal。它的工作原理类似于,但使用了我在 中建议的\temporal\AltBeamer alt 命令“喜欢可见”而不是“喜欢仅”。此外,我还添加了一个可选参数,可用于将较窄的替代方案对齐到左侧、中间或右侧([l][c][r])。这对于支持居中数组单元是必要的。

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

% Test the different modes and math styles
\begin{frame}<1-3>
Display:
\[
\begin{split}
\frac{dy}{dx} &= \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right)
\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}.
\end{split}
\]

In-Text:
\(
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right)
\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}.
\)

Subscript:
\(
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right) X_{\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}}.
\)
\[
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right) X_{\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}}.
\]

Sub-Subscript:
\(
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right) X_{X_{\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}}}.
\)
\[
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right) X_{X_{\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}}}.
\]

Text-mode:
XXXX  \Temporal<2>{aaaaa}{Ag}{AAAA}.


\end{frame}
\begin{frame}<1-3>
    \[ \left(
    \begin{array}{ccc}
        \Temporal<2>[r]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} & 
        \Temporal<2>[c]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} & 
        \Temporal<2>[l]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} \\
        \Temporal<2>[l]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} & 
        \Temporal<2>[c]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} & 
        \Temporal<2>[r]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} \\
        \Temporal<2>[c]{<2}{=2}{>2} &
        \Temporal<2>{\int x}{\iint x}{\oint x} \\
    \end{array}
        \right)
    \]

\end{frame}
\end{document}

幻灯片 1 幻灯片 2 幻灯片 3

(图片尺寸差异是由于不同的裁剪造成的)

答案2

马丁的解决方案非常棒!

不幸的是,至少存在一种情况,\Temporal和的\Alt表现并不如人们所愿:在数组中使用它,人们可能会对数组感兴趣,其中需要交换一些行。\Temporal会产生错误,而\temporal不会。

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

相关内容