我想在方程式下方写一些文本,点击后文本会发生变化。请考虑以下示例
\documentclass[12pt, a4paper,xcolor=dvipsnames]{beamer}
\begin{document}
\begin{frame}
\begin{align*}
a^2+b^2=c^2
\end{align*}
\only<1> {Some text on the first Slide, \\
that explains some things \\
and some more text}
\only<2> {Some other text on second Slide, \\
which is slightly shorter}
\end{frame}
\end{document}
在第二张幻灯片中,由于文本较短,公式向下跳动。如何避免这种情况?
答案1
您可以使用overlayarea
环境来停止幻灯片中文本的抖动。以下语法和文档取自 Beamer 用户指南。
\begin{overlayarea}{⟨area width⟩}{⟨area height⟩}
⟨environment contents⟩
\end{overlayarea}
环境中的所有内容都将放置在指定大小的矩形区域中。无论其实际内容如何,该区域在帧的所有幻灯片上都将具有相同的大小。
对于您的示例,以下内容将起作用:
\documentclass[12pt, a4paper,xcolor=dvipsnames]{beamer}
\begin{document}
\begin{frame}
\begin{align*}
a^2+b^2=c^2
\end{align*}
\begin{overlayarea}{\linewidth}{0.5\textheight}
\only<1> {Some text on the first Slide, \\
that explains some things \\
and some more text}
\only<2> {Some other text on second Slide, \\
which is slightly shorter}
\end{overlayarea}
\end{frame}
\end{document}
这样会生成文本不会跳动的 pdf。
答案2
改用\onslide
;它在不可见时保留空间。
\onslide<1> {Some text on the first Slide, \\
that explains some things \\
and some more text}
\onslide<2> {Some other text on second Slide, \\
which is slightly shorter}
答案3
一种方法是使用相同的垂直空间(使用包)使<only>
命令的文本开始和结束calc
。请注意,这种方式也需要开始
\vspace
添加一些非常长的文本或方程式。
\documentclass[12pt, a4paper,xcolor=dvipsnames]{beamer}
\usepackage{calc}
\newdimen\mycurrentheight
\newdimen\mymaxheight
\newdimen\myspace
\newdimen\zerodimen
\newsavebox{\mybox}
\def\keepHeight#1{
\setbox\mybox\vbox{#1}
\setlength{\mycurrentheight}{\ht\mybox+\dp\mybox}
\addspace{\mycurrentheight}
\usebox{\mybox}
\vskip \myspace
}
\def\addspace#1{
\ifdim\mycurrentheight>#1
\let\mymaxheight=\mycurrentheight
\let\myspace=\zerodimen
\else
\let\myspace=\zerodimen
\advance \myspace by \mymaxheight
\advance \myspace by -\mycurrentheight
\fi
}
\begin{document}
\begin{frame}
\vspace*{-50pt}
\begin{align*}
a^2+b^2=c^2
\end{align*}
\only<1> {\keepHeight{ Some text on the first Slide, \\
that explains some things \\
and some more text}}
\only<2> {\keepHeight{ Some other text on second Slide, \\
which is slightly shorter}}
\only<3> {\keepHeight{Some text on the third Slide, \\
that explains some things \\
and some more text and an equation \[x=4-7\]
using much more space than the previous.}}
\only<4> {\keepHeight{ Some other text on fourth Slide, \\
which is shorter}}
\only <5> {Here we don't keep the height}
\end{frame}
除最后一帧之外的每一帧的结果都是完美“垂直对齐”的。
答案4
你可以使用一个技巧。添加 \phantom{some text} 来获得所需的行为。
\documentclass[12pt, a4paper,xcolor=dvipsnames]{beamer}
\begin{document}
\begin{frame}
\begin{align*}
a^2+b^2=c^2
\end{align*}
\only<1> {Some text on the first Slide, \\
that explains some things \\
and some more text}
\only<2> {Some other text on second Slide, \\
which is slightly shorter \\
\phantom{bla}}
\end{frame}
\end{document}