本文介绍 LaTeX 插图以及多图排版的用法,值得注意的是 figure 环境一个浮动体环境,LaTeX 不总是浮动体放在你想要的地方,但是 LaTeX 总是保证浮动体的相对顺序,所以对图片 \label
和 \ref
的交叉引用就显得尤为重要。
插图的基本命令 1 2 3 4 5 6 \begin {figure}[hbp]\centering \includegraphics [width=0.7textwidth]{图片文件名称}\caption {图片标题名称}label{fig1}\end {figure}
hbp
允许浮动体排版在当前位置、底部或者单独成页。table 和 figure 浮动体的默认设置为 tbp
。!hbp
表示一定把图片放在当前页上,或放在页面底部,或放在一专门页面,不管页面是否美观。
h
当前位置(代码所处的上下文)
t
顶部
b
底部
p
单独成页
!
在决定位置时忽视限制
注 1: 排版位置的选取与参数里符号的顺序无关,LaTeX 总是以 h-t-b-p 的优先级顺序决定浮动体位置。也就是说 [!htp]
和 [ph!t]
没有区别。
注 2: 限制包括浮动体个数(除单独成页外,默认每页不超过 3 个浮动体,其中顶部不超过 2 个,底部不超过 1 个)以及浮动体空间占页面的百分比(默认顶部不超过 70%,底部不超过 30%)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \documentclass {article}\usepackage {graphicx}\usepackage {mwe}\begin {document}How can I put two figures side-by-side? Not two sub-figures, but two actual figures with separate "Fig.: bla bla" captions. \begin {figure}[htbp]\centering \includegraphics [width=0.6\textwidth ]{example-image-a}\caption {Dummy Caption A.}\end {figure}A figure is supposed to spread over the entire text width, but I have two figures which are narrow and long, and I need to save the space in order to withstand the pages limit. \end {document}
两图并排,共享标题 1 2 3 4 5 6 7 \begin {figure}[htb]\centering \includegraphics [width=0.48\linewidth ]{example-image-a}\hfill \includegraphics [width=0.48\linewidth ]{example-image-b}\caption {Left: Dummy Caption A, Right: Dummy Caption B}\end {figure}
两图并排,独立标题 1 2 3 4 5 6 7 8 9 10 11 12 13 \begin {figure}[htb]\centering \begin {minipage}{0.48\linewidth }\centering \includegraphics [width=\linewidth ]{example-image-a}\caption {Dummy Caption A.}\end {minipage}\hfill \begin {minipage}{0.48\linewidth }\centering \includegraphics [width=\linewidth ]{example-image-b}\caption {Dummy Caption B.}\end {minipage}\end {figure}
如果图片大小不一致,可以用加一个选项 [t]
保证图片的底部对齐。(比较推荐 )
1 2 3 4 5 6 7 8 9 10 11 12 13 \begin {figure}[htb]\centering \begin {minipage}[t]{0.48\linewidth }\centering \includegraphics [width=\linewidth ]{example-image-a}\caption {Dummy Caption A.}\end {minipage}\hfill \begin {minipage}[t]{0.48\linewidth }\centering \includegraphics [width=0.8\linewidth ]{example-image-b}\caption {Dummy Caption B.}\end {minipage}\end {figure}
使用 subfig
宏包 1 2 3 4 5 6 7 8 \begin {figure}[htb]\centering \subfloat [Subcaption A]{\includegraphics [width=0.48\linewidth ]{example-image-a}}\hfill \subfloat [Subcaption B]{\includegraphics [width=0.48\linewidth ]{example-image-b}}\caption {Two figures.}\end {figure}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 \begin {figure}[htb]\centering \subfloat [Subcaption A]{\includegraphics [width=0.32\linewidth ]{example-image-a}}\hfill \subfloat [Subcaption B]{\includegraphics [width=0.32\linewidth ]{example-image-b}}\hfill \subfloat [Subcaption C]{\includegraphics [width=0.32\linewidth ]{example-image-c}} \\ \subfloat [Subcaption A]{\includegraphics [width=0.32\linewidth ]{example-image-a}}\hfill \subfloat [Subcaption B]{\includegraphics [width=0.32\linewidth ]{example-image-b}}\hfill \subfloat [Subcaption C]{\includegraphics [width=0.32\linewidth ]{example-image-c}}\caption {Six figures.}\end {figure}
使用 subcaption
宏包 1 2 3 4 5 6 7 8 \begin {figure}[htb]\centering \subcaptionbox {Dummy Subcaption A.}{\includegraphics [width=0.48\linewidth ]{example-image-a}}\hfill \subcaptionbox {Dummy Subcaption B.}{\includegraphics [width=0.48\linewidth ]{example-image-b}}\caption {Dummy Caption.}\end {figure}
参考资料