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


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


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


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


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


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