[Tex/LaTex] Width of the caption of a figure

captionswidth

I am having trouble making the caption beneath a figure to be of same width of the figure (less than the width of the paragraphs in the same page). How can I force the caption width to be the same as the figure width?

Best Answer

The caption package provides a width parameter than can be set for each figure individually. This way you can adjust the width to suit the width of your figure:

enter image description here

\documentclass{article}

\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{lipsum}% Just for this example
\usepackage{graphicx,caption}

\begin{document}

\begin{figure}[t]
  \centering
  \captionsetup{width=.8\linewidth}
  \includegraphics[width=.8\linewidth, height=3\baselineskip]{example-image-a}
  \caption[First figure]{\lipsum*[2]}
\end{figure}

\lipsum[1]

\begin{figure}[t]
  \centering
  \captionsetup{width=.9\linewidth}
  \includegraphics[width=.9\linewidth, height=3\baselineskip]{example-image-b}
  \caption[Second figure]{\lipsum*[2]}
\end{figure}

\end{document}

If all your figures have the same width, you can set the option \captionsetup{width=<len>} globally.