Alterning images in beamer is shifting to right
Asked Answered
J

1

14

When I am trying to do alternating images in beamer with usage of the \only and overlayarea like this:

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

the image is moving to the right more and more on the each slide. Let's say, that in the 1. slide is in the position x, in the second slide in the position x+5 and in the third slide x+10.

Why? How can I fix it?

Jujube answered 3/10, 2014 at 20:30 Comment(0)
P
25

You have what is referred to as a spurious space between usages of \only. While spreading out your code for readability purposes might work well, sometimes these spaces cause unwanted output in your resulting PDF. Use % to keep the readability but avoid the spacing issues:

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}
Periodical answered 4/10, 2014 at 4:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.