# Beamer: left-aligned caption of centered figure

I am doing which should be a simple task, but I cannot fathom why it does not work... I just want a simple caption of a figure I centered, aligned to the left of the figure, right down its lower left corner.

This is my MWE:

\documentclass{beamer}

\mode<presentation> {
\usepackage[labelformat=empty,
font=scriptsize,
skip=0pt,
justification=justified,
singlelinecheck=false]{caption}
}

\begin{document}

\begin{frame}
\begin{center}
\includegraphics[width=.5\linewidth]{example-image}
\captionof{figure}{my caption here}
\end{center}
\end{frame}

\end{document}


Which produces:

How can I have the caption right below the bottom left corner of my image? And why does the code above not work?

Please note the solution should also work within a \figure environment to add captions to tikzpictures...

Thanks!

EDIT: I TRIED justification=justified,singlelinecheck=false AS SUGGESTED HERE, BUT STILL NO SUCCESS...

\documentclass{beamer}

\usepackage[labelformat=empty,font=scriptsize,skip=0pt,
justification=raggedright,singlelinecheck=false]{caption}

\begin{document}

\begin{frame}
\begin{center}
\includegraphics[width=.5\linewidth]{example-image}
\captionof{figure}{my caption here}
\end{center}
\end{frame}

\end{document}


You can use package threeparttable to restrict the caption width to the width of the image:

\documentclass{beamer}

\usepackage{threeparttable}
\usepackage[labelformat=empty,font=scriptsize,skip=0pt,
justification=raggedright,singlelinecheck=false]{caption}

\begin{document}

\begin{frame}
\begin{figure}
%\centering% not needed, because default
\begin{measuredfigure}
\includegraphics[width=.5\linewidth]{example-image}
\caption{my caption here}
\end{measuredfigure}
\end{figure}
\end{frame}

\end{document}


Usually you do not need explicit center or \centering, because beamer centers the figure by default (see the result in the image above). Instead, if you want left aligned or right aligned figures you have to add \raggedright or \raggedleft just after \begin{figure}. Nevertheless, you can activate the commented \centering.

• This is it! Isn't the use of "measuredfigure" and "figure" redundant though? Only with "measuredfigure" I get the same result Jan 29, 2017 at 11:34
• @DaniCee Without figure the image wouldn't be centered by default. So you would need an additional environment to center it. Jan 29, 2017 at 11:37
• what about without "figure" but with "centering"? Jan 29, 2017 at 11:44
• @DaniCee \centering would center the whole frame not only the picture. center could be used, but why not using figure? center would be physical markup, figure is semantic markup. Semantic markup should be preferred, because you can change all figures at once in the preamble of the document. It would make more sense to redefine figure to be a centered measuredfigure than to put all measuredfigure into a center-environment. But I do not recommend to do so, because if you would have a very small image, a measuredfigure could be very ugly. Jan 29, 2017 at 11:48
• for the win: How would you align the caption to the right side instead? I tried with \raggedleft before the caption, but nothing happened... Feb 1, 2017 at 11:44

Wrapping the image and its caption in an additional minipage could be a solution:

\documentclass{beamer}
\setbeamertemplate{caption}{\insertcaption}

\begin{document}

\begin{frame}
\begin{figure}
\begin{minipage}{.4\textwidth}
\includegraphics[width=\textwidth]{example-image}
\caption{Text text text text text text text text text text text text text text text text text}
\end{minipage}
\end{figure}
\end{frame}

\end{document}


• But a single line caption would be centered without using package caption. AFAIK the OP want it left aligned with the image. Jan 30, 2017 at 12:19

I think, using a floating object like the \begin{figure} ... \end{figure} or \begin{table} ... \end{table} is in conflict of the needs of a presentation. A floating object is something, which LaTeX may move around to get the best possible word, line and page wrapping. Therefore it may move the image to the end of the chapter. In a presentation, you don't want to jump forth and back between your slides. You normally want a continuous flow from one slide to the next.

Having said that, you don't want to use a floating object in beamer, at least not in the presentation forms.

Having said that, you don't want to use \caption-like commands, as you don't have a figure-environment.

The solution in your case: just remove the \caption-command (and even the caption-package) and it works.

MWE:

\documentclass{beamer}

\begin{document}

\begin{frame}
\begin{center}
\includegraphics[width=.5\linewidth]{example-image}\\
my caption here
\end{center}
\end{frame}

\end{document}


Result:

• I don't really understand why the use of captions is not recommended in Beamer... this is the first time I read something like this. Jan 29, 2017 at 8:46
• The problem is I have way more complicated layouts than that in the MWE, so in those cases what should I do to replace the captions?? put the figure in a tikzpicture node and the caption as text in another node? that sounds really overly complicating things... Jan 29, 2017 at 8:47
• I don't think floats are the problem here. I can't try right now but: have you tried removing the grouping braces around the \usepackage command? \mode<presentation> does not take arguments afaik Jan 29, 2017 at 9:22
• figure and table in beamer are not floating. They are placed where they are used. See section 12.6 in the beamer user manual. Jan 29, 2017 at 10:37
• @Jan In beamer you can just as well use figure, as it is redefinded to do basically not much more then centering ... Jan 29, 2017 at 11:38