[Tex/LaTex] Separation between caption and subcaption

captionsspacingsubcaption

Consider the following MWE

\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
  \begin{subfigure}[t]{.5\linewidth}
    \centering
    \rule{3cm}{3cm}
    \caption{First subfigure}
  \end{subfigure}%
  \begin{subfigure}[t]{.5\linewidth}
    \centering
    \rule{3cm}{3cm}
    \caption{Second subfigure}
  \end{subfigure}
\caption{A figure}
\end{figure}
\end{document}

How do I reduce from the preamble (either as a package option or a setting) the separation between the caption of the subfigures and the caption of the figure?

Best Answer

It is mostly an optical effect. The vertical space is the same as the one used between figure and caption, but it is measured from the bottom, which in the case of subfigures is at the lowest point in the parentheses.

Here's the proof:

\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}

\DeclareRobustCommand{\vr}[1]{\smash{\rule{0.2pt}{#1}}}
\DeclareRobustCommand{\hr}{\makebox[0pt][l]{\rule{10cm}{0.2pt}}}

\begin{document}

\begin{figure}[htp]
\centering
    \rule{6cm}{3cm}
\caption{A figure\vr{18pt}}
\end{figure}

\begin{figure}[htp]
  \begin{subfigure}[t]{.5\linewidth}
    \centering
    \rule{3cm}{3cm}
    \caption{\hr First subfigure}
  \end{subfigure}%
  \begin{subfigure}[t]{.5\linewidth}
    \centering
    \rule{3cm}{3cm}
    \caption{Second subfigure}
  \end{subfigure}

\caption{A figure\vr{18pt}}
\end{figure}
\end{document}

I added rules to show the spacing; the rule in the upper figure almost touches the black box; in the bottom case, it almost touches the level of the parentheses. Actually there is 1pt more in the bottom case, due to \lineskip.

enter image description here

If you want that the vertical spacing is measured from the baseline of the subfigures and your subcaptions are always one liners, then you might add

\AtBeginDocument{%
  \def\endsubfigure{%
    \par % ensure vertical mode
    {\small\sbox0{()}\kern-\dp0}% back up by the depth of ()
    \kern-\lineskip
    \endminipage
  }%
}

and the result would be

enter image description here

However, the backing up would be too much if a subcaption breaks across lines.

A much easier method would be

\captionsetup{skip=\dimexpr\abovecaptionskip-3pt}
\caption{A figure}

adjusting the 3pt to suit in the cases where this seems necessary. This will reduce the skip between the objects (subfigures and caption) by the stated amount.