42

Figure captions seem to wrap at the page width. How could I make them wrap at the figure width instead? Currently, they can easily be mistaken for normal text.

\begin{figure}[!htb]
    \begin{center
    \begin{tikzpicture} ... \end{tikzpicture}
    \caption{Caption goes here.}
    \end{center}
\end{figure}

pdf example

2

5 Answers 5

48

The caption package provides many enhancements: for example

\usepackage[margin=1cm]{caption}

Reducing the caption to the figure width seems not a good idea in general, particularly if a couple of figures are on the same page or on facing pages. On the other hand reducing the width and maybe the font size can be a good typographical device to isolate them better from the context.

11
  • 4
    The OP seems to want to adapt caption widths to the widths of individual figures, not to reduce the caption width by a fixed amount.
    – lockstep
    Sep 20, 2011 at 17:49
  • Yes, you're right. I'll edit the answer.
    – egreg
    Sep 20, 2011 at 17:51
  • 2
    @egreg: You convinced me that decreasing the caption width with a constant amount would be better. Thanks!
    – Tim N
    Sep 20, 2011 at 18:00
  • 1
    @Nomi Hmm, what top and bottom margins?
    – egreg
    Aug 25, 2016 at 21:38
  • 2
    @Nomi That's the job of abovecaptionskip and belowcaptionskip
    – egreg
    Aug 26, 2016 at 16:15
6

in caption package guide:

Only fixed widths are supported here; if you are looking for a way to limit the width of the caption to the width of the figure or table, please take a look at the floatrow[8] or threeparttable[22] package.

\documentclass{article}
\usepackage{floatrow}
\begin{document}

\begin{figure}
\ffigbox[\FBwidth]
{\caption{caption text caption text caption text caption text 
caption text caption text caption text caption text 
caption text caption text caption text caption text }\label{...}}
{\rule{50mm}{20mm}}
\end{figure}

\end{document}
1
  • Hadi Safi aghdam - that works, but it doesn't respect 'width' options of includegraphics. That is, the caption is much wider than the figure with something like this: \begin{figure} \ffigbox[\FBwidth] {\caption{caption text caption text caption text caption text caption text caption text caption text caption text }\label{...}} {\includegraphics[width=.4\linewidth]{dummy}} \end{figure} Feb 3, 2014 at 17:09
6

I also encountered the problem. Sometimes I use therefore two minipages to put two figures beside each other, so not much vertical space is lost.

\documentclass{article}
\usepackage{caption}
\begin{document}
 \begin{figure}
   \begin{minipage}[b]{0.6\textwidth}
     \centering
     \rule{0.4\textwidth}{3cm}
     \captionof{figure}{%
       Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
       Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.
       Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
     }
     \label{fig:a}
   \end{minipage}\hfill
   \begin{minipage}[b]{0.3\textwidth}
     \centering
     \rule{0.8\textwidth}{3cm}
     \captionof{figure}{%
       Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
       Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.
     }
     \label{fig:b}
   \end{minipage}
 \end{figure}
\end{document}

enter image description here

6

Additionally to @egreg's answer, it's worth noting that caption also has a localised parameter that can be set:

\captionsetup{margin=3cm}

Otherwise globally using the package option \usepackage[margin=1cm]{caption} as suggested.

You can get the documentation here.

An example:

\begin{figure}
    \centering
    \captionsetup{margin=3cm}
    \includegraphics[width=\textwidth]{filename}
    \caption{long ... amounts  .... of ... text}
\end{figure}
3
  • 1
    \setlength{\captionmargin}{3cm} is the same as \captionsetup{margin=3cm} but the latter should be used now.
    – user2574
    Jun 5, 2018 at 16:31
  • @AxelSommerfeldt thanks, updated to newer syntax
    – Mr G
    Jun 5, 2018 at 23:07
  • The caption can be extended beyond the width of the text by using negative numbers, e.g. \captionsetup{margin=-1cm}. Sep 3, 2021 at 10:43
0

You can use the wrapfigure environment also like so:

\begin{wrapfigure}{r}{0.5\textwidth}
    \includegraphics[] {MyFigure}
    \centering
    \caption{My nifty caption}
    \label{fig_something_to_reference_with}
\end{wrapfigure}

This will create a smaller environment containing your figure and the caption and then wrap the surrounding text around it.

Additional information can be found at https://www.sharelatex.com/learn/Inserting_Images

1
  • Welcome to TeX.SX! This does not only limit the caption width, but also changes the figure's position.
    – TeXnician
    Sep 30, 2017 at 6:17

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.