Width of the caption of a figure

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.


Instead of using a predetermined width, one can measure the width using a savebox and put the caption inside a minipage.

\documentclass{article}
\usepackage{graphicx}
\usepackage{blindtext}

\begin{document}
\begin{figure}
\sbox0{\includegraphics{example-image}}% measure width
\centering
\begin{minipage}{\wd0}
  \usebox0
  \caption{\blindtext}
\end{minipage}
\end{figure}

\end{document}

demo


Probably the simplest solution is to put the figure in a measuredfigure environment, from the threeparttable package. Note however this environment is fragile and might require being protected:

\documentclass[12pt, a4paper, twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{heuristica}
\usepackage[textwidth =15cm]{geometry}

\usepackage{graphicx}
\usepackage{caption, threeparttable}
\captionsetup{labelfont = sc, textfont = it}

\begin{document}
\begin{figure}
\centering\captionsetup{format = hang}
\begin{measuredfigure}
\includegraphics{Piero_di_Cosimo_3}
\caption{Portrait of Simonetta Vespucci\label{sen}}
 \end{measuredfigure}
 \end{figure}

\end{document}

enter image description here

Another, more powerful, possibility, consists in using the floatrow environment and setting its optional width argument as \FBwidth (= float box width):

\documentclass [11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ebgaramond}
\usepackage{graphicx, caption} %
\usepackage{floatrow}

\usepackage{lipsum}
\captionsetup{font = small, labelsep = period}

\begin{document}

\lipsum[11]
\begin{figure}[!htb] % <-- see difference between your code and this MWE
\centering
\begin{floatrow}[1]
\ffigbox[\FBwidth]{\caption{Max Ernst: \emph{Two Children are treatened by a Nightingale} (1924)} \label{max_ernst}}%
{\includegraphics[scale = 0.75]{ernst-nightingale}}
\end{floatrow}
\end{figure}
\lipsum[14]

\end{document} 

enter image description here

Tags:

Width

Captions