Beamer中的图像切换向右移动

13

当我尝试在beamer中使用\onlyoverlayarea来交替显示图片时,代码如下:

\begin{frame}
    \frametitle{Tasks}

    \begin{overlayarea}{\textwidth}{\textheight}
        \begin{figure}
            \centering
            \only<1>
                {
                    \includegraphics[width=0.3\textwidth]{img/noise_detail_2.png}
                }
            \only<2>
                {
                    \includegraphics[width=0.3\textwidth]{img/noise_detail_2.png}
                }
            \only<3>
                {
                    \includegraphics[width=0.3\textwidth]{img/noise_detail_2.png}
                }
            \only<4>
                {
                    \includegraphics[width=0.3\textwidth]{img/noise_detail_2.png}
                }
        \end{figure}
    \end{overlayarea}      
\end{frame}

每张幻灯片中图像向右移动越来越多。假设第一张幻灯片上的位置为x,第二张幻灯片上的位置为x+5,第三张幻灯片上的位置为x+10

为什么会这样?我该如何解决?

1个回答

24

你在\only使用之间有所谓的伪空格。虽然为了可读性而展开代码可能很有效,但有时这些空格会导致生成PDF时产生不需要的输出。使用%保持可读性并避免间距问题

enter image description here

\documentclass{beamer}
\begin{document}

\begin{frame}
  \frametitle{Tasks}

  \begin{overlayarea}{\textwidth}{\textheight}
    \begin{figure}
      \centering
      \only<1>
        {%
          \includegraphics[width=.8\textwidth]{example-image-a}%
        }%
      \only<2>
        {%
          \includegraphics[width=.8\textwidth]{example-image-b}%
        }%
      \only<3>
        {%
          \includegraphics[width=.8\textwidth]{example-image-c}%
        }%
    \end{figure}
  \end{overlayarea}      
\end{frame}

\end{document}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接