7

I have the following document:

\documentclass{article}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage{geometry}
\setcaptionwidth{12cm}
\begin{document}
\begin{figure}[t]
  \centering%
  \subfloat[]{\label{figa}\includegraphics[width=38mm,%
    height=32.48mm]{fig1}}\hspace{3mm}%
  \subfloat[]{\label{figb}\includegraphics[width=38mm,%
    height=32.48mm]{fig2}}\hspace{3mm}%
  \subfloat[]{\label{figc}\includegraphics[width=38mm,%
    height=32.48mm]{fig3}}%
  \caption{Some caption.}
  \label{fig-moire-comp-xue}
\end{figure}
\end{document}

I want the captions of all figures to have a width of 12cm (slightly less than main body text), and have TeX generate the (a), (b) labels for me.

This is the result:

Incorrect image

If I then comment out the line in the preamble setting the caption width to 12cm, it aligns as I want:

Correct image

(This is an issue in my thesis, a much more complicated document, but I think I have narrowed it down to this conflict.) I just want the alignment to be fixed, but still have 12cm wide captions for all figures.

I don't really care if the solution is an ugly per-figure hack, I just care about alignment.

Thanks for any help.

6

You can set globally the caption's width and separately the subcaption's width:

\captionsetup{width=12cm}
\captionsetup[subfloat]{margin=0pt}

Don't use \setcaptionwidth, of course (it is an obsolete command of caption version 2).w

3

set the captionwidth before the caption itself:

\documentclass{article}
\usepackage{subfig}
\usepackage[demo]{graphicx}
\usepackage{geometry}
\begin{document}
\begin{figure}
  \centering%
  \subfloat[]{\label{figa}\includegraphics[width=38mm,%
    height=32.48mm]{fig1}}\hspace{3mm}%
  \subfloat[]{\label{figb}\includegraphics[width=38mm,%
    height=32.48mm]{fig2}}\hspace{3mm}%
  \subfloat[]{\label{figc}\includegraphics[width=38mm,%
    height=32.48mm]{fig3}}%
  \setcaptionwidth{12cm}
  \caption{Some very long caption to show that is not
           wider than 12 cm as defined by the setting.}
  \label{fig-moire-comp-xue}
\end{figure}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.