4

I am trying to create an overlay of two pictures in Beamer. The first one has a caption and the second one doesn't. I tried using \captionof but the caption keeps appearing on the second slide.

\documentclass[xcolor=x11names,compress]{beamer}

\usepackage{graphicx}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\captionsetup{font=scriptsize,labelformat=empty}



\begin{document}

\begin{frame}
\centerline{\includegraphics<1>[width=10cm]{Pic1}}%
\captionof{figure}{caption of 1st pic} 
\centerline{\includegraphics<2>[width=10cm, height=7cm]{Pic2}}%
\end{frame}

\end{document}

Thanks.

an1234
  • 165
  • 1
    Don't use captions in presentations. They don't make sense. Put descriptions directly under the images. – percusse Jun 27 '13 at 10:09

1 Answers1

5

The problem arises as \captionof is not overlay-aware, thus a possible solution is to pack within an \only both \includegraphics and \captionof.

An example:

\documentclass[xcolor=x11names,compress]{beamer}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{caption}
\captionsetup{font=scriptsize,labelformat=empty}
\usepackage{mwe} % for dummy images


\begin{document}

\begin{frame}
\centering
\only<1>{
\includegraphics[width=10cm]{example-image-a}%
\captionof{figure}{caption of 1st pic} 
}
\includegraphics<2>[width=10cm, height=7cm]{example-image-b}%
\end{frame}

\end{document}

The result:

enter image description here

However, as you can see, a bad jumping effect comes due to the different height of image+caption with respect to image only. Thus to overcome the issue, one could proceed as follows:

\documentclass[xcolor=x11names,compress]{beamer}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{caption}
\captionsetup{font=scriptsize,labelformat=empty}
\usepackage{mwe} % for dummy images


\begin{document}

\begin{frame}
\begin{overlayarea}{\textwidth}{0.875\textheight}
\centering
\only<1>{
\includegraphics[width=10cm]{example-image-a}%
\captionof{figure}{caption of 1st pic} 
}
\includegraphics<2>[width=10cm, height=7cm]{example-image-b}%
\end{overlayarea}
\end{frame}

\end{document}

The result:

enter image description here

For more insights see Get a includegraphic to stick in the same place for several beamer slides.

  • This is great I just have one minor issue...the pictures are not vertically centered inside of the frame...In this question link it says to use \parbox instead of overlay but that doesn`t seem to work in my example. – an1234 Jun 27 '13 at 09:25
  • 1
    @an1234: the vertical center depends on several things, actually. Here you can just reduce a bit the size of the overlayarea, i.e. 0.75\textheight and it should work. But, beware: if you add text, if you add a title the situation will change. – Claudio Fiandrino Jun 27 '13 at 09:29