Separation between caption and subcaption
Set the skip
option, provided by caption
. As suggested in the caption
documentation, "[t]he vertical space between the caption and the figure or table contents is controlled by skip=<amount>
":
\documentclass{article}
\usepackage{caption,subcaption,graphicx}
\begin{document}
\begin{figure}[t]
\begin{subfigure}[t]{.5\linewidth}
\centering
\includegraphics[width=3cm]{example-image-a}
\caption{First subfigure}
\end{subfigure}%
\begin{subfigure}[t]{.5\linewidth}
\centering
\includegraphics[width=3cm]{example-image-b}
\caption{Second subfigure}
\end{subfigure}
\caption{A figure}
\end{figure}
\begin{figure}[t]
\captionsetup{skip=0pt}
\begin{subfigure}[t]{.5\linewidth}
\centering
\includegraphics[width=3cm]{example-image-a}
\caption{First subfigure}
\end{subfigure}%
\begin{subfigure}[t]{.5\linewidth}
\centering
\includegraphics[width=3cm]{example-image-b}
\caption{Second subfigure}
\end{subfigure}
\caption{A figure}
\end{figure}
Hello world.
\end{document}
You can also set this in the document preamble.
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
.
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
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.