# 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?

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:

\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.

• Thanks werner for the quick answer.! LaTeX Error: Option clash for package geometry. I get this error when I use the package {lipsum}, do you have any idea? Sep 19, 2014 at 15:33
• @Naema: Both geometry and lipsum were just for this example. The latter is really not necessary in your document as it just creates dummy text, Lorem Ipsum-style. The former you might use, but then there should be no problem.
– Werner
Sep 19, 2014 at 15:51

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}


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}


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}