3

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:

fig1

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}

b

4

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}

caption below image restricted to image width

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.

| improve this answer | |
  • This is it! Isn't the use of "measuredfigure" and "figure" redundant though? Only with "measuredfigure" I get the same result – DaniCee Jan 29 '17 at 11:34
  • @DaniCee Without figure the image wouldn't be centered by default. So you would need an additional environment to center it. – Schweinebacke Jan 29 '17 at 11:37
  • what about without "figure" but with "centering"? – DaniCee Jan 29 '17 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. – Schweinebacke Jan 29 '17 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... – DaniCee Feb 1 '17 at 11:44
3

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}

enter image description here

| improve this answer | |
  • But a single line caption would be centered without using package caption. AFAIK the OP want it left aligned with the image. – Schweinebacke Jan 30 '17 at 12:19
1

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:

enter image description here

| improve this answer | |
  • 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. – DaniCee Jan 29 '17 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... – DaniCee Jan 29 '17 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 – gigabytes Jan 29 '17 at 9:22
  • Right, it's the singlelinecheck=false argument what causes it... But without it the caption is centered below the image; I'd like the caption to be aligned left with the image... I am editing to reflect this – DaniCee Jan 29 '17 at 9:27
  • 1
    @Jan In beamer you can just as well use figure, as it is redefinded to do basically not much more then centering ... – samcarter_is_at_topanswers.xyz Jan 29 '17 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.