Graphics, Figures & TablesHow to change the vspace of subfigures to a fixed value?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
loujing
Posts: 9
Joined: Mon Jun 01, 2015 7:13 pm

How to change the vspace of subfigures to a fixed value?

Post by loujing »

My demo code is as follows.
How to change the vspace of subfigures and caption to a fixed value as shown in the uploaded figure (totally 4 places), e.g. 2pt?

Code: Select all

\documentclass{article}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}

bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 

\begin{figure}[!htb]
	\begin{center}
	    \subfloat[caption]{\includegraphics[width=0.33\textwidth]{example-image-a}\hspace{1pt}%
	    }
	    \subfloat[caption]{\includegraphics[width=0.33\textwidth]{example-image-b}\hspace{1pt}%
	    }
	    \subfloat[caption]{\includegraphics[width=0.33\textwidth]{example-image-c}
	    }
	\end{center}
	\begin{center}
	    \subfloat[caption]{\includegraphics[width=0.33\textwidth]{example-image-a}\hspace{1pt}%
 	    }
 	    \subfloat[caption]{\includegraphics[width=0.33\textwidth]{example-image-b}\hspace{1pt}%
 	    }
 	    \subfloat[caption]{\includegraphics[width=0.33\textwidth]{example-image-c}
 	    }
	\end{center} 	 
	\caption{MAIN CAPTION}
\end{figure}

bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 

\end{document}
QQ截图20161006034514.png
QQ截图20161006034514.png (53.7 KiB) Viewed 23871 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

How to change the vspace of subfigures to a fixed value?

Post by rais »

loujing wrote: How to change the vspace of subfigures and caption to a fixed value as shown in the uploaded figure (totally 4 places), e.g. 2pt?
The {center} environment adds vertical space upon opening and closing. Within a float, such as {figure}, this vertical space is normally not wanted, because the float surrounds itself by vertical space of its own.
The first thing you should do is: remove both {center} environments from your {figure} and use the \centering command instead.

In your case, the space between text above and the {figure}---(a)---is controlled by \intextsep, the additional space from {center}, and subfig's farskip option.
Between the subfloats (b), you get additional space from closing the first and opening the second {center} environment, plus nearskip (from the first row of subfloats: skip below the (sub) caption, zero by default), and farskip (from the second row of subfloats: skip above the subfigure)---I'd keep this space bigger than `captionskip' (skip between subfigure and subcaption), not to confuse the reader by pushing a caption closer to a subfigure it's not the caption for...
Between the last subfloats and the main caption (c), you get additional space from closing the second {center} environment, plus nearskip (from second row of subfloats), plus caption's skip option for {figure} environment.
Between {figure} and text below (d), you get \intextsep, plus a possible \belowcaptionskip (for the latter, see caption).

For figures placed top or bottom, you may also need to affect \floatsep.

KR
Rainer
loujing
Posts: 9
Joined: Mon Jun 01, 2015 7:13 pm

How to change the vspace of subfigures to a fixed value?

Post by loujing »

rais wrote:
loujing wrote: How to change the vspace of subfigures and caption to a fixed value as shown in the uploaded figure (totally 4 places), e.g. 2pt?
The {center} environment adds vertical space upon opening and closing. Within a float, such as {figure}, this vertical space is normally not wanted, because the float surrounds itself by vertical space of its own.
The first thing you should do is: remove both {center} environments from your {figure} and use the \centering command instead.

In your case, the space between text above and the {figure}---(a)---is controlled by \intextsep, the additional space from {center}, and subfig's farskip option.
Between the subfloats (b), you get additional space from closing the first and opening the second {center} environment, plus nearskip (from the first row of subfloats: skip below the (sub) caption, zero by default), and farskip (from the second row of subfloats: skip above the subfigure)---I'd keep this space bigger than `captionskip' (skip between subfigure and subcaption), not to confuse the reader by pushing a caption closer to a subfigure it's not the caption for...
Between the last subfloats and the main caption (c), you get additional space from closing the second {center} environment, plus nearskip (from second row of subfloats), plus caption's skip option for {figure} environment.
Between {figure} and text below (d), you get \intextsep, plus a possible \belowcaptionskip (for the latter, see caption).

For figures placed top or bottom, you may also need to affect \floatsep.

KR
Rainer
Thanks a lot for your advice. They are all valuable and very helpful.
Post Reply