2

My question is:

How to adjust the gap between figure and caption within the same subfloat

Not the gap between two subfloat.

For the following example:

\begin{figure}
    \centering
    \subfloat[A]{\includegraphics[ scale=0.5]{images/a.jpg}}
    \vspace{-10pt}
    \subfloat[B]{\includegraphics[scale=0.5]{images/b.jpg}}
    \vspace{-10pt}
    \caption{}\label{fig:online_test}
\end{figure}

I got the following figure:

enter image description here

The sub-caption of (a) is too close to the sub-figure B. I hope the caption (a) to stay closer to sub-figure A. How can I adjust the space between the caption and figure within a subfloat?

Thank you all for helping me and I would prefer a solution for subfloat, instead of using other packages. But I would also appreciate a solution of using other packages.

I know my question looks similar to this question. But please make it clear. I'm asking for how to adjust the gap between figure and caption within a subfloat, not the gap between two subfloat. That is, the gap between the caption "a" and the figure "A"

Thank you.

  • 2
    You've asked this question before. An edit would have been more appropriate I think. However, please complete the MWE. – TeXnician Aug 12 '17 at 9:26
3

your have more problems:

  • with your code i can't reproduce provided images. they are in one line ...
  • problem is probably in images, which have white space below image. to check this, put image in \fbox{...} like

\subfloat[A]{\fbox{\includegraphics[scale=0.5]{images/a.jpg}}}

and see, if the frame is tied width image

  • other causes can be in your document preamble, which you not show. for example the following mwe

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\usepackage[skip=1ex]{caption}

\begin{document}
\begin{figure}
    \centering
    \subfloat[A]{\fbox{\includegraphics[scale=0.5]{images/a.jpg}}}

    \subfloat[B]{\includegraphics[scale=0.5]{images/b.jpg}}
    \caption{}\label{fig:online_test}
\end{figure}
\end{document}

gives the following result:

enter image description here

  • distance between subfloat[...]{...} and caption is determined with option \package[skip=1ex]{caption}. this set vertical space determined by skip globally. if you like to change only for this image, than please add after \begin{figure}

\captionsetup{skip=<desired value}
  • Thank you. Yes there is large white space in my figure. I will revise it. But my question is not answered. Is there any way to adjust the gap I mentioned? Thank you very much!! – pfc Aug 12 '17 at 9:45
  • how is not answered? gap is set to 1ex. see preamble, how caption is loaded. if this you not liked, change skip to value, which like to have. for example to \usepackage[skip=5ex]{caption} – Zarko Aug 12 '17 at 9:52
4

The subfig package provides a native option for this, which is the captionskip=<glue> option. You can either pass it when loading the package (for it to affect globally, i.e. all subfloats) or use

\captionsetup[subfloat]{captionskip=40pt} % You can use any value you like here.

within your figure environment to localise the effect. (Obviously I am exaggerating the value here to prove my point).

\documentclass{article}
\usepackage{subfig} % Replace with \usepackage[captionskip=40pt]{subfig} to set this globally
\usepackage{graphicx}
\begin{document}
\begin{figure}
    \captionsetup[subfloat]{captionskip=40pt} % <------------ Not required, if option is passed globally
    \centering
    \subfloat[A]{\includegraphics[]{example-image}}\\
    \subfloat[B]{\includegraphics[]{example-image}}
    \caption{}\label{fig:online_test}
\end{figure}
\begin{figure}
    \centering
    \subfloat[A]{\includegraphics[]{example-image}}\\
    \subfloat[B]{\includegraphics[]{example-image}}
    \caption{}
\end{figure}
\end{document}

Example: I demonstrate here the 'local' case.

[40pt] caption skip gives:

enter image description here

as opposed to: default caption skip gives:

enter image description here


Side note: Please always provide a compilable code, starting with \documentclass and ending with \end{document} like I have above. This way, everyone can copy-paste the code and compile it without further additions.

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.