我有一系列想要制作动画的图像beamer
。在每一帧中,我希望有两幅图像,例如 A 和 B,垂直对齐并位于页面中央。所有图像大小相同。
我尝试使用 对齐图像\vspace{}
,但是当我穿过图像时,垂直空间会累积并且图像会向下滑动。
我应该如何对齐每一帧中的图像?
这是一个最小的工作示例:
\documentclass{beamer}
\begin{document}
\frame{
\begin{figure}[t!]
\includegraphics<1>[scale=.5]{fig/imageA1} \vspace{.1in}
\includegraphics<1>[scale=.5]{fig/imageB1}
\includegraphics<2>[scale=.5]{fig/imageA2} \vspace{.1in}
\includegraphics<2>[scale=.5]{fig/imageB2}
\includegraphics<3>[scale=.5]{fig/imageA3} \vspace{.1in}
\includegraphics<3>[scale=.5]{fig/imageB3}
\includegraphics<4>[scale=.5]{fig/imageA4} \vspace{.1in}
\includegraphics<4>[scale=.5]{fig/imageB4}
\end{figure}
}
\end{document}
答案1
在框架中使用浮动环境(例如 figure
或table
)无法正常工作。要实现您的目标,请打开allowpagebreak
和T
。使用 选项调整图形height
。请参阅下面的代码以了解其余部分。
\documentclass{beamer}
\usepackage{graphicx}
\begin{document}
\frame[allowpagebreak,T]
{%
\only<1>
{%
\centering
\includegraphics[height=\dimexpr0.5\textheight-0.5in]{example-image-a}
\vfill
\includegraphics[height=\dimexpr0.5\textheight-0.5in]{example-image-a}
}%
\only<2>
{%
\centering
\includegraphics[height=\dimexpr0.5\textheight-0.5in]{example-image-b}
\vfill
\includegraphics[height=\dimexpr0.5\textheight-0.5in]{example-image-b}
}%
\only<3>
{%
\centering
\includegraphics[height=\dimexpr0.5\textheight-0.5in]{example-image-c}
\vfill
\includegraphics[height=\dimexpr0.5\textheight-0.5in]{example-image-c}
}%
\only<4>
{%
\centering
\includegraphics[height=\dimexpr0.5\textheight-0.5in]{example-image}
\vfill
\includegraphics[height=\dimexpr0.5\textheight-0.5in]{example-image}
}%
}
\end{document}
有关创建 GIF 动画,请参阅我的另一个答案在这里。
答案2
除了\vspace
,您还可以使用\\
来强制换行。
\documentclass{beamer}
\begin{document}
\frame{
\begin{figure}[t!]
\includegraphics<1>[scale=.5]{img} \\
\includegraphics<1>[scale=.5]{img}
\includegraphics<2>[scale=.5]{img} \\
\includegraphics<2>[scale=.5]{img}
\includegraphics<3>[scale=.5]{img} \\
\includegraphics<3>[scale=.5]{img}
\includegraphics<4>[scale=.5]{img} \\
\includegraphics<4>[scale=.5]{img}
\end{figure}
}
\end{document}
答案3
如果您总共只有一个换行符,而不是每个图像对都有一个换行符,那么您的问题应该会消失。关键是您的\vspace{.1in}
命令没有被<1>
、<2>
、<3>
或屏蔽<4>
:
\documentclass{beamer}
\begin{document}
\frame{
\begin{figure}[t!]
\includegraphics<1>[scale=.5]{fig/imageA1}
\includegraphics<2>[scale=.5]{fig/imageA2}
\includegraphics<3>[scale=.5]{fig/imageA3}
\includegraphics<4>[scale=.5]{fig/imageA4}
\vspace{.1in}
\includegraphics<1>[scale=.5]{fig/imageB1}
\includegraphics<2>[scale=.5]{fig/imageB2}
\includegraphics<3>[scale=.5]{fig/imageB3}
\includegraphics<4>[scale=.5]{fig/imageB4}
\end{figure}
}
\end{document}