# Positioning of image with caption

I have some issues with positioning an image with the help of textpos-package. I want the figure to be positioned as in frame 1, but with a centered caption (like in frame 2). I tried to put the image in a figure environment, but this seems to change the behaviour of positioning. Any ideas?

Thanks

Nico

Here's my code

\documentclass{beamer}
\usepackage{graphicx, caption}
\usepackage[absolute,overlay]{textpos}
\setbeamertemplate{background}[grid][step=0.25cm]

\begin{document}

% without a figure environment, the image is positioned as expected
\begin{frame}{Frame 1}
\begin{textblock*}{\paperwidth}(0cm,0cm)
\includegraphics[scale=0.5]{example-image-a}
\end{textblock*}
\end{frame}

% figure environment changes positioning
\begin{frame}{Frame 2}
\begin{textblock*}{\paperwidth}(0cm,0cm)
\begin{figure}
\includegraphics[scale=0.5]{example-image-a}
\caption{Example-Image A}
\end{figure}
\end{textblock*}
\end{frame}

\end{document}


Producing

You could use \captionof from the caption package, which you are already loading. To get the caption centred you have to ensure that your textblock and image have the same width.

Please note that it is not necessary to load graphicx, beamer already provides this functionality.

\documentclass{beamer}
\usepackage{
%graphicx,
caption}
\usepackage[absolute,overlay]{textpos}
\setbeamertemplate{background}[grid][step=0.25cm]

\begin{document}

% without a figure environment, the image is positioned as expected
\begin{frame}{Frame 1}
\begin{textblock*}{.5\paperwidth}(0cm,0cm)
\includegraphics[width=.5\paperwidth]{example-image-a}
\captionof{figure}{Example}
\end{textblock*}
\end{frame}

% figure environment changes positioning
\begin{frame}{Frame 2}
\begin{textblock*}{\paperwidth}(0cm,0cm)
\begin{figure}
\includegraphics[scale=0.5]{example-image-a}
\caption{Example-Image A}
\end{figure}
\end{textblock*}
\end{frame}

\end{document}


• Thanks for your answer and also for the hint with graphicx-package. I didn‘t know that beamer loads the package already. – Nico Aug 1 '18 at 17:09
• I just found out that your solution doesn't completely solve my problem. I didn't mention it explicitly in the question, but I must scale the images because they are pdfs of different tikz-trees with the same node style. The amount of nodes in each graphic is different (so they have different lenghts and heights). To have the same node sizes on each image, I have to scale the pdfs with the same factor. Can you think about a solution that uses scale- instead of width-key? – Nico Aug 2 '18 at 6:56
• @Nico You could have a look at the original size of each image and use your scaling factor to calculate the required width of the textblock. – user36296 Aug 2 '18 at 7:53