在 Beamer 中居中图像并进行套印

在 Beamer 中居中图像并进行套印

我正在尝试创建一个beamer演示文稿,其中的几张图片在连续的幻灯片上相互替换。我已让它与overprint和配合使用\onslide,但无法使图片在幻灯片上居中。

\begin{center}
  \begin{overprint}
    \onslide<2>\includegraphics[scale=0.3]{images/stack1.pdf}    
    \onslide<3>\includegraphics[scale=0.3]{images/stack2.pdf}
    \onslide<4>\includegraphics[scale=0.3]{images/stack3.pdf}
    \onslide<5>\includegraphics[scale=0.3]{images/stack4.pdf}
    \onslide<6>\includegraphics[scale=0.3]{images/stack5.pdf}
    \onslide<7>\includegraphics[scale=0.3]{images/stack6.pdf}
    \onslide<8>\includegraphics[scale=0.3]{images/stack7.pdf}
  \end{overprint}
\end{center}

环境之外的任何事物overprint都会正确居中,但图像本身则不会。

答案1

环境overprint具有固定宽度,默认为\textwidth(或可能类似\linewidth),可以使用可选参数指定。然后整个环境居中,而不仅仅是其中的图像,它们在内部左对齐。因为环境已经与给定空间一样宽,所以居中实际上不会改变其位置。您需要将区域内的图像居中(overprint例如使用\centerline{\includegraphics[..]{..}}}或者手动将环境缩小overprint到图像宽度,以便有效地居中。

\documentclass{beamer}

\begin{document}

\begin{frame}{Test}
  \begin{center}
  text before
  \pause
  \begin{overprint}%
    \onslide<2>\centerline{\includegraphics[scale=0.3]{images/stack1.pdf}}%
    \onslide<3>\centerline{\includegraphics[scale=0.3]{images/stack2.pdf}}%
    \onslide<4>\centerline{\includegraphics[scale=0.3]{images/stack3.pdf}}%
    \onslide<5>\centerline{\includegraphics[scale=0.3]{images/stack4.pdf}}%
    \onslide<6>\centerline{\includegraphics[scale=0.3]{images/stack5.pdf}}%
    \onslide<7>\centerline{\includegraphics[scale=0.3]{images/stack6.pdf}}%
    \onslide<8>\centerline{\includegraphics[scale=0.3]{images/stack7.pdf}}%
  \end{overprint}
  text after
  \end{center}
\end{frame}

\end{document}

或者

\documentclass{beamer}

\begin{document}

\begin{frame}{Test}
    \begin{center}
  text before
  \pause

  \begin{overprint}[7cm]%
    \onslide<2>\includegraphics[width=7cm]{images/stack1.pdf}%
    \onslide<3>\includegraphics[width=7cm]{images/stack2.pdf}%
    \onslide<4>\includegraphics[width=7cm]{images/stack3.pdf}%
    \onslide<5>\includegraphics[width=7cm]{images/stack4.pdf}%
    \onslide<6>\includegraphics[width=7cm]{images/stack5.pdf}%
    \onslide<7>\includegraphics[width=7cm]{images/stack6.pdf}%
    \onslide<8>\includegraphics[width=7cm]{images/stack7.pdf}%
  \end{overprint}%

  text after
  \end{center}
\end{frame}

\end{document}

scalewidth这里替换了键,以确保图像的宽度与overprint环境的宽度相同。我更喜欢第一个\centerline解决方案,因为您不必匹配任何宽度。

相关内容