[Tex/LaTex] Centering subfloat caption with subfig package

captionssubfloats

A footnote on page 12 of the subfig documentation says in part:

Note that the ‘width’ may be larger than the width of the
sub-float body, or equivalently, the ‘width’ may be negative to provide more room for a caption if the
sub-float body is small. The box holding the caption is centered relative to the sub-float body.

I must not be understanding something.

First, by looking at Figure 91 on page 35, don't they mean to say that you can set the margin to a negative value in order to get a caption that is wider than (and centered relative to) the sub-float body?

Even if this is right, I can't get a simple example to work. See my MWE below.

What am I doing wrong?

MWE:

\documentclass{article}
\usepackage{caption}
\usepackage{subfig}
\begin{document}
\begin{figure}[ht]
 \centering
 \subfloat[very long subfloat caption]{
  \framebox[3cm][c]{
   subfloat body
  }
 }
\end{figure}
\begin{figure}[ht]
 \centering
 \captionsetup[subfloat]{width=-2cm}
 \subfloat[very very long subfloat caption]{
  \framebox[3cm][c]{
   subfloat body
  }
 }
\end{figure}
\begin{figure}[ht]
 \centering
 \captionsetup[subfloat]{margin=-2cm}
 \subfloat[very very long subfloat caption]{
  \framebox[3cm][c]{
   subfloat body
  }
 }
\end{figure}
\end{document}

enter image description here

Best Answer

You can fool subfig letting it think that the subfloat is, e.g., \textwidth wide, by inserting the subfloat body in a box of that width.

Example:

\documentclass{article}
\usepackage{subfig}
\begin{document}
\begin{figure}[ht]
 \centering
 \subfloat[very very very very very long subfloat caption]{%
  \makebox[\textwidth]{\framebox[3cm][c]{subfloat body}}%
 }
\end{figure}
\end{document} 

Output:

enter image description here