我正在尝试创建一个由 7 个子图组成的图形,其布局如下:
第一行和第二行各有 3 个子图(左对齐、居中、右对齐)
第三行有一个子图(左对齐)。
我写的代码是:
\begin{figure}[h]
\begin{subfigure}[t!]{0.4 \textwidth}
\includegraphics[scale=0.25]{./capitoli/4/immagini/a_1.png}
\end{subfigure}
\begin{subfigure}[t!]{0.4 \textwidth}
\includegraphics[scale=0.23]{./capitoli/4/immagini/a_2.png}
\end{subfigure}
\begin{subfigure}[t!]{0.2 \textwidth}
\includegraphics[scale=0.24]{./capitoli/4/immagini/a_3.png}
\end{subfigure}
\begin{subfigure}[c!]{0.25 \textwidth}
\includegraphics[scale=0.35]{./capitoli/4/immagini/a_4.png}
\end{subfigure}
\begin{subfigure}[c!]{0.2 \textwidth}
\includegraphics[scale=0.35]{./capitoli/4/immagini/a_5.png}
\end{subfigure}
\begin{subfigure}[c!]{0.2 \textwidth}
\includegraphics[scale=0.35]{./capitoli/4/immagini/a_6.png}
\end{subfigure}
\begin{subfigure}[b!]{0.2 \textwidth}
\includegraphics[scale=0.35]{./capitoli/4/immagini/a_7.png}
\end{subfigure}
\end{figure}
但它在第一行打印两个子图,然后在五行打印一个左对齐的子图。
有什么建议可以解决这个问题吗?
答案1
由于您除了\subfigures
不同的width
s 之外还有不同大小的图形,因此在我看来很难通过仅添加例如\hfill
和来实现所需的布局\\
(这对于具有相同尺寸的图形很有效):
代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[h]
\begin{subfigure}[t]{0.4\textwidth}
\includegraphics[scale=0.25]{example-image-a}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[scale=0.23]{example-image-a}
\end{subfigure}%
\hfill
\begin{subfigure}[t]{0.2\textwidth}
\includegraphics[scale=0.24]{example-image-a}
\end{subfigure}%
\\
\begin{subfigure}[b]{0.25\textwidth}
\includegraphics[scale=0.35]{example-image-b}
\end{subfigure}%
\hfill
\begin{subfigure}[b]{0.2\textwidth}
\includegraphics[scale=0.35]{example-image-b}
\end{subfigure}%
\hfill
\begin{subfigure}[b]{0.2\textwidth}
\includegraphics[scale=0.35]{example-image-b}
\end{subfigure}%
\\
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[scale=0.35]{example-image-c}
\end{subfigure}%
\hfill
\end{figure}
\end{document}
因此,根据代码的输出,一种简单的方法是使用环境 tabular
。使用l
、c
和 ,r
您可以分别将图形对齐到左侧、中间或右侧;。
输出:
代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[h]
\centering
\begin{tabular}{lcr}
\includegraphics[scale=0.25]{example-image-a} &
\includegraphics[scale=0.23]{example-image-a} &
\includegraphics[scale=0.24]{example-image-a} \\
\includegraphics[scale=0.35]{example-image-b} &
\includegraphics[scale=0.35]{example-image-b} &
\includegraphics[scale=0.35]{example-image-b} \\
\includegraphics[scale=0.35]{example-image-c} & & \\
\end{tabular}
\end{figure}
\end{document}
答案2
根据您问题中呈现的图像,我假设:
- 它们大小相同,
- 他们没有字幕
因此可以简单排列如下图所示:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htb]
\setkeys{Gin}{width=0.3\linewidth}
\includegraphics{example-image-duck}
\hfill
\includegraphics{example-image-duck}
\hfill
\includegraphics{example-image-duck}
\smallskip
\includegraphics{example-image-duck}
\hfill
\includegraphics{example-image-duck}
\hfill
\includegraphics{example-image-duck}
\smallskip
\includegraphics{example-image-duck}
\caption{My beautiful images. Quack!}
\label{tab:traintestsplit}
\end{figure}
\end{document}
注意,图像或文本之间的空行开始新的文本行。