[Tex/LaTex] Vertically aligning images in beamer

beamergraphicsvertical alignment

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}

Best Answer

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.