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?
Asked
Active
Viewed 1.3e+01k times
58
3 Answers
69
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.
Werner
- 603,163
-
2Thanks 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? – Naema Sep 19 '14 at 15:33
-
2@Naema: Both
geometryandlipsumwere 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 '14 at 15:51
17
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}
John Kormylo
- 79,712
- 3
- 50
- 120
13
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}
Bernard
- 271,350


\documentclass{...}and ending with\end{document}. – Sep 19 '14 at 15:13boxhandlerpackage will automatically make captions the same width as the figure/table, unless overridden (no width need be specified). However, it requires you to enter figures/tables in macro, rather than environment form. Examples: http://tex.stackexchange.com/questions/101212/caption-format-changing/101217#101217 and/or http://tex.stackexchange.com/questions/110393/too-wide-figure-caption/110453#110453 – Steven B. Segletes Sep 19 '14 at 15:34