Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a sequence of images I would like to animate in beamer. In each frame, I would like to have two images, say A and B, aligned vertically and centred on the page. All images are the same size.

I tried aligning the images using \vspace{}, but then the vertical spaces accumulate and the images slide down as I transition through them.

How should I align the images in each frame?

Here is a minimal working example:

\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}
share|improve this question
    
Did you try to add a blank line between two images and insert the vertical space there? –  Sigur Apr 12 '13 at 0:55
2  
No need to use [t!] since beamer disables the floating mechanism. –  Gonzalo Medina Apr 12 '13 at 1:02
    
Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code as I did in my edit. –  Kurt Apr 12 '13 at 1:12
    
@GonzaloMedina That's good to know, I didn't realize that. –  abayesed Apr 12 '13 at 1:44
1  
@Sigur see my response to Kevin. –  abayesed Apr 12 '13 at 1:46

3 Answers 3

up vote 5 down vote accepted

Using floating environments (such as figure or table) in a frame does not work in the way it should. To accomplish your objective, turn on allowpagebreak and T. Adjust the graphics with height option. See the code below for the remaining.

enter image description here

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

For creating GIF animation see my other answer here.

share|improve this answer
    
Thanks for this solution, it works. How did you generate the gif, by the way? –  abayesed Apr 12 '13 at 1:48
    
@abayesed: If it works the way you want, why don't you accept it with a green check mark below the downward arrow? I will show you how to generate GIF soon. –  cyanide-based food Apr 12 '13 at 1:50
    
sorry, I didn't realize you were supposed to do that. This is my first post on TeX.sx. –  abayesed Apr 12 '13 at 1:53
    
Why do you say using figure doesn't work? It It won't produce a floating object (since beamer disables them), but it gives the possibility of using \caption. –  Gonzalo Medina Apr 12 '13 at 4:03
    
@GonzaloMedina: See my comment several days ago. –  cyanide-based food Apr 12 '13 at 4:10

Instead of \vspace, you can use \\ to force a line break.

\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}
share|improve this answer
    
I tried forcing a line break this way, but I get an error when I compile saying "There's no line here to end". –  abayesed Apr 12 '13 at 1:43

If you only have one line break in total instead of one for every image pair, your problem should disappear. The point is that your \vspace{.1in} commanded is not masked by the <1>,<2>,<3>, or <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}
share|improve this answer
    
Thanks! This is the simplest solution. –  abayesed Apr 12 '13 at 1:39
    
Using figure does not make sense in beamer. –  cyanide-based food Apr 12 '13 at 1:52
    
@Karl'sstudents why is that? –  abayesed Apr 12 '13 at 1:58
    
@abayesed: Because floating in a frame does not work. –  cyanide-based food Apr 12 '13 at 2:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.