LaTeX 子图排版和子图垂直对齐

LaTeX 子图排版和子图垂直对齐

本文参考:

三个宏包的选择

Package subfigure – Deprecated: Figures divided into subfigures

The pack­age is now con­sid­ered ob­so­lete: it was su­per­seded by sub­fig, but users may find the more re­cent sub­cap­tion pack­age more sat­is­fac­tory.

subfigure 包已经被废弃,推荐使用 subfig 包。如果想要使用更加新的宏包,就用 subcaption 包。

使用例

subfig

Example using the subfig package:

1
2
3
4
5
6
7
8
\begin{figure}%
\centering
\subfloat[First.]{...}\qquad
\subfloat[Second figure.]{...}\\
\subfloat[Third.]{\label{3figs-c}...}%
\caption{Three sub-floats.}
\label{3figs}
\end{figure}

caption 和 subcaption

caption and subcaption

1
2
3
4
5
6
7
8
9
\usepackage[%
font={small,sf},
labelfont=bf,
format=hang,
format=plain,
margin=0pt,
width=0.8\textwidth,
]{caption}
\usepackage[list=true]{subcaption}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  \begin{figure}
\centering

\subcaptionbox{Subcaption A}{
\includegraphics[width=0.20\textwidth]{example-image-a}
}

\hfill

\subcaptionbox{Subcaption B}{
\includegraphics[width=0.20\textwidth]{example-image-b}
}

\hfill

\subcaptionbox{Subcaption C}{
\includegraphics[width=0.20\textwidth]{example-image-c}
}

\hfill

\subcaptionbox{Subcaption D}{
\includegraphics[width=0.20\textwidth]{example-image}
}

\caption{Caption}
\end{figure}

subcaption with hfill

子图垂直对齐

subcaption

The optional argument for the subfigure environment provides the placement of the sub-caption anchor. This is used to align the sub-captions vertically.

subcaption align

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
\documentclass{article}

\usepackage{graphicx,subcaption}

\begin{document}

\begin{figure}
\centering
\texttt{subfigure} with \texttt{[t]}op alignment

\medskip

\begin{subfigure}[t]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}
\begin{subfigure}[t]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\begin{subfigure}[t]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-c}
\caption{This is a sub-caption. This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

\texttt{subfigure} with \texttt{[c]}entre alignment (default)

\medskip

\begin{subfigure}{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}
\begin{subfigure}{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\begin{subfigure}{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-c}
\caption{This is a sub-caption. This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

\texttt{subfigure} with \texttt{[b]}ottom alignment

\medskip

\begin{subfigure}[b]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}
\begin{subfigure}[b]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\begin{subfigure}[b]{.3\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-c}
\caption{This is a sub-caption. This is a sub-caption.}
\end{subfigure}
\end{figure}

\end{document}

对于不同尺寸的图片进行垂直对齐:

subcaption spread

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
\documentclass{article}

\usepackage{graphicx,subcaption}

\newsavebox{\imagebox}

\begin{document}

\begin{figure}
\centering

Default

\medskip

\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth,height=75pt]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\qquad
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth,height=5pc]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

\verb|\raisebox| to vertical top

\medskip

% Store largest image in a box
\savebox{\imagebox}{
\includegraphics[width=.2\linewidth,height=75pt]{example-image-a}
}%

\begin{subfigure}[t]{.4\linewidth}
\centering\usebox{\imagebox} % Place largest image
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\qquad
\begin{subfigure}[t]{.4\linewidth}
\centering\raisebox{\dimexpr\ht\imagebox-\height}{% Raise smaller image into place
\includegraphics[width=.5\linewidth,height=5pc]{example-image-b}}%
\caption{This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

\verb|\raisebox| to vertical centre

\medskip

% Store largest image in a box
\savebox{\imagebox}{
\includegraphics[width=.2\linewidth,height=75pt]{example-image-a}
}%

\begin{subfigure}[t]{.4\linewidth}
\centering\usebox{\imagebox}% Place largest image
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\qquad
\begin{subfigure}[t]{.4\linewidth}
\centering\raisebox{\dimexpr.5\ht\imagebox-.5\height}{% Raise smaller image into place
\includegraphics[width=.5\linewidth,height=5pc]{example-image-b}}%
\caption{This is a sub-caption.}
\end{subfigure}

\end{figure}

\end{document}

子图水平分布

subcaption

subcaption spread

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
\documentclass{article}

\usepackage{graphicx,subcaption}
\usepackage[margin=1cm,showframe]{geometry}% Just for this example

\begin{document}

\begin{figure}
\centering

Fixed separation using \verb|\quad| (or \verb|\qquad|, or \verb|\hspace|)

\medskip

\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\quad
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}

\bigskip\hrulefill\bigskip

Even spread via \verb|\hfill|

\medskip

\mbox{}\hfill
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\hfill
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}
\hfill\mbox{}

\bigskip\hrulefill\bigskip

Full spread via \verb|\hfill|

\medskip

\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-a}
\caption{This is a sub-caption. This is a sub-caption. This is a sub-caption}
\end{subfigure}\hfill
\begin{subfigure}[t]{.4\linewidth}
\centering\includegraphics[width=.5\linewidth]{example-image-b}
\caption{This is a sub-caption.}
\end{subfigure}

\end{figure}

\end{document}

多行子图使用例

many sub figures

1
2
3
4
5
6
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{subfigure}
\usepackage{subfloat}
\usepackage{float}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 \begin{figure*}[ht!]
\centering
\subfigure[]
{
\label{subfig:lab1}
\includegraphics[width=.3\textwidth]{figures/1.pdf}
}
%
\subfigure[]
{
\label{subfig:lab2}
\includegraphics[width=.3\textwidth]{figures/2.pdf}
}
%
\subfigure[]
{
\label{subfig:lab3}
\includegraphics[width=.3\textwidth]{figures/3.pdf}
}\\ % for new row or line of subfigures
%
\subfigure[Caption 4]
{
\label{subfig:lab4}
\includegraphics[width=.3\textwidth]{figures/4.pdf}
}
%
\subfigure[Caption 5]
{
\label{subfig:lab6}
\includegraphics[width=.3\textwidth]{figures/5.pdf}
}
%
\subfigure[Caption 6]
{
\label{subfig:lab6}
\includegraphics[width=.3\textwidth]{figures/6.pdf}
}
%
\caption{Figure Caption}
\label{fig:Figure ref}
\end{figure*}

LaTeX 子图排版和子图垂直对齐
https://taylorandtony.github.io/2025/03/21/LaTeX-子图排版和子图垂直对齐/
作者
TaylorAndTony
发布于
2025年3月21日
许可协议