0

I have to position different figures in exact overlapping positions where each figure is on a different frame. Besides figures, there is some text too with each figure and therefore this answer does not work because there is text too.

The problem is that the figures do not position correctly if the text exists. Like in the following MWE the sixth frame has some text "hello" and due to this the position of B offsets from all other perfectly overlapping figures.

I guess there needs to be some absolute positioning required to position the sixth figure correctly but I do not know how to capture the position coordinates of the figure just before it in order to define the position of the displaced figure. Sorry, I am a novice in the beautiful world of TeX. :)

Any leads would be helpful. Thank you.

 \documentclass{beamer}
    \usepackage{tikz}
    \usepackage{capt-of}
    \begin{document}
    
    \begin{frame}
    \begin{center}
      \begin{tikzpicture}
        \node<1> (img1) {\includegraphics[width=.5\linewidth]{example-image-a}};
        \node<2> (img2) {\includegraphics[width=.5\linewidth]{example-image-b}};
        \node<3> (img3) {\includegraphics[width=.5\linewidth]{example-image-c}};
      \end{tikzpicture}
    \end{center}
    \end{frame}
    
    \begin{frame}
    \begin{center}
      \begin{tikzpicture}
        \node<1> (img1) {\includegraphics[width=.5\linewidth]{example-image-a}};
        % \node<2> (img2) {\includegraphics[width=.5\linewidth]{example-image-b}};
        % \node<3> (img3) {\includegraphics[width=.5\linewidth]{example-image-c}};
      \end{tikzpicture}
    \end{center}
    \end{frame}
    
    \begin{frame}
    hello
    \begin{center}
      \begin{tikzpicture}
        % \node<1> (img1) {\includegraphics[width=.5\linewidth]{example-image-a}};
        \node<1> (img2) {\includegraphics[width=.5\linewidth]{example-image-b}};
        % \node<3> (img3) {\includegraphics[width=.5\linewidth]{example-image-c}};
      \end{tikzpicture}
    \captionof{figure}{A caption.}
    \end{center}
    \end{frame}
    
    \begin{frame}
    \begin{center}
      \begin{tikzpicture}
        % \node<1> (img1) {\includegraphics[width=.5\linewidth]{example-image-a}};
        % \node<2> (img2) {\includegraphics[width=.5\linewidth]{example-image-b}};
        \node<1> (img3) {\includegraphics[width=.5\linewidth]{example-image-c}};
      \end{tikzpicture}
    \end{center}
    \end{frame}
    \end{document}

1 Answer 1

1

This may not be a perfect solution. Using tikz remember picture,overlay option to put the figure in the absolute center position of the page. Then you need carefully decide where to type text and caption, otherwise they may overlap the figure. That's why I put \vspace{5.5cm} between the hello word and caption text. However, all the figures will at the exact same locations of each frame. See to follow code. Hope it can meet your requirement.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{caption}
\begin{document}
\begin{frame}
\begin{tikzpicture}[remember picture,overlay]
\only<1>{\node (img1) at (current page.center) {\includegraphics[width=.5\linewidth]{example-image-a}};}
\only<2>{\node (img2) at (current page.center) {\includegraphics[width=.5\linewidth]{example-image-b}};}
\only<3>{\node (img3) at (current page.center) {\includegraphics[width=.5\linewidth]{example-image-c}};}
\only<4>{\node (img3) at (current page.center) {\includegraphics[width=.5\linewidth]{example-image-a}};}
\end{tikzpicture}
\only<3>{hello
\vspace{5.5cm}\captionof{figure}{A caption.}}
\end{frame}
\end{document}

enter image description here

Edit: Don't know exact what you want type in. Here is an example of potential different text positions. I use node inside the tikzpicture to place the caption. You could use node inside the tikzpicture to place text as well. In this way, they will be at absolute same location in different frames. I added [t] option in the frame env as well. This will make the text aligned from top of the frame (default is [c], center aligned). So now is easier to use \vspace{} to position the text.

\documentclass{beamer}
\usepackage{tikz}
\usepackage{caption}
\begin{document}
\begin{frame}[t]
\begin{tikzpicture}[remember picture,overlay]
\only<1>{\node (img1) at (current page.center) {\includegraphics[width=.5\linewidth]{example-image-a}};}
\only<2>{\node (img2) at (current page.center) {\includegraphics[width=.5\linewidth]{example-image-b}};}
\only<3>{\node (img3) at (current page.center) {\includegraphics[width=.5\linewidth]{example-image-c}};\node [text width=\linewidth,below] at (img3.south) {\captionof{figure}{A caption.}};}
\only<4>{\node (img4) at (current page.center) {\includegraphics[width=.5\linewidth]{example-image-a}};\node [text width=\linewidth,below] at (img4.south) {\captionof{figure}{B caption.}};}
\end{tikzpicture}
\only<3>{
\vspace{1cm}\begin{center}Title Name\end{center}
}
\only<4>{\par\vspace{3.75cm} hello word!
}
\end{frame}
\end{document}

enter image description here

5
  • That’s cool. How can we center the “hello” or position it anywhere in the slide?
    – kaka
    Jun 8, 2022 at 5:00
  • @kaka You could use \begin{center}hello\end{center}.
    – Tom
    Jun 8, 2022 at 5:06
  • 1
    @kaka I edited the answer to include some examples.
    – Tom
    Jun 8, 2022 at 5:53
  • I notice that captions Figure: A and Figure: B are not overlaying when "hello word" is added. Can we overlay the captions too without being affected by anything else on the slide 4? Thanks
    – kaka
    Jun 8, 2022 at 22:04
  • 1
    @kaka See the new edits in the answer.
    – Tom
    Jun 8, 2022 at 22:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .