[Tex/LaTex] Center subfloat above extended subcaption in subfig package

horizontal alignmentsubcaptionsubfloatswidth

In the subfig package, the command \captionsetup[subfigure]{width=<length>} extends the width of a subcaption. Now how can the subfloats be centered above their enlarged subcaptions? The subfloats appear to be left justified by default.

Best Answer

You could put the subfigure object into a \makebox[<width>][c]{...} via a macro:

\captionsetup[subfigure]{width=5em}
\newcommand{\includesubfig}[2][]{%
  \makebox[5em][c]{\includegraphics[#1]{#2}}}%

and then use

\subfloat[ToC-entry][This is a very long subcaption that should span a couple of lines]%
  {\includesubfig{fig}}%

Here is a draft of what it looks like where my figure consists of \rule{20pt}{30pt}:

\documentclass{article}
\usepackage{subfig}
\newsubfloat{figure}
\captionsetup[subfigure]{width=5em}
\begin{document}
  ​\begin{figure}
    \subfloat[test1][This is a very long caption that should span over a couple of lines]{\makebox[5em][c]{\rule{20pt}{30pt}}}
    \caption{This is caption for the figure}
  \end{figure}
​\end{document}​​​​​​​

Centered subfloat/subfigure

Alternatively, if you only do this for limited number of subfigures, then manually using the \makebox[<width>][c]{...} should suffice, as I did in the minimal example above.

Related Question