我尝试使用以下代码将 6 幅图像放入 3x2 图像框中:
\begin{figure}[H]
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_1.png}\quad
\caption{image1}
\label{fig:1}
\end{subfigure}%
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_2.png}\quad
\caption{image2}
\label{fig:2}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}\quad
\centering
\includegraphics[width=.8\linewidth]{imp_3.png}
\caption{image3}
\label{fig:3}
\end{subfigure}
\medskip
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_4.png}\quad
\caption{image4}
\label{fig:4}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_5.png}\quad
\caption{image5}
\label{fig:5}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_6.png}
\caption{image6}
\label{fig:6}
\end{subfigure}
\caption{Fasi del processo di impregnazione}
\label{fig:images}
\end{figure}
我获得了我想要的 3 列 2 行的图像,但是第一行的第三张图像向右移动了,我不知道如何修复它。
感谢您的帮助!
答案1
还有一个建议:
- 使图形内容居中
\centering
- 在子图形之间插入
\hfil
- 目的
\quad
不明确,请将其删除 - 内容居中
subfigure
是多余的。最好使子图宽度更小,并使图宽度适应子图的宽度
完整代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption,subcaption}
\usepackage[showframe]{geometry}
\begin{document}
\begin{figure}[htb]
\centering % <-- added
\begin{subfigure}{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{image1}
\label{fig:1}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\caption{image2}
\label{fig:2}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\caption{image3}
\label{fig:3}
\end{subfigure}
\medskip
\begin{subfigure}{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{image4}
\label{fig:4}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\caption{image5}
\label{fig:5}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\caption{image6}
\label{fig:6}
\end{subfigure}
\caption{Fasi del processo di impregnazione}
\label{fig:images}
\end{figure}
\end{document}
结果是:
答案2
您在第三个 \includegraphics 之前执行了 \quad 并将其移到其后面,就像在其他情况下一样,应该可以修复它。
\begin{figure}[H]
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_1.png}\quad
\caption{image1}
\label{fig:1}
\end{subfigure}%
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_2.png}\quad
\caption{image2}
\label{fig:2}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}%"\quad" not here since this will insert a spacing before the image.
\centering
\includegraphics[width=.8\linewidth]{imp_3.png}\quad %but here
\caption{image3}
\label{fig:3}
\end{subfigure}
\medskip
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_4.png}\quad
\caption{image4}
\label{fig:4}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_5.png}\quad
\caption{image5}
\label{fig:5}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp_6.png}
\caption{image6}
\label{fig:6}
\end{subfigure}
\caption{Fasi del processo di impregnazione}
\label{fig:images}
\end{figure}
答案3
我认为你不需要那些 \quads。在行之间添加一个空白行。
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption, subcaption}
\usepackage[showframe]{geometry}
\begin{document}
\begin{figure}[H]
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp₁.png}
\caption{image1}
\label{fig:1}
\end{subfigure}%
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp₂.png}
\caption{image2}
\label{fig:2}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}\quad
\centering
\includegraphics[width=.8\linewidth]{imp₃.png}
\caption{image3}
\label{fig:3}
\end{subfigure}
\medskip
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp₄.png}
\caption{image4}
\label{fig:4}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp₅.png}
\caption{image5}
\label{fig:5}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
\centering
\includegraphics[width=.8\linewidth]{imp₆.png}
\caption{image6}
\label{fig:6}
\end{subfigure}
\caption{Fasi del processo di impregnazione}
\label{fig:images}
\end{figure}
\end{document}
答案4
请检查一下:
\documentclass{article}
\usepackage{graphicx,subfigure}
\begin{document}
\begin{figure}[t!]
\centering
\subfigure[image1]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\subfigure[image2]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\subfigure[image3]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad\\
\subfigure[image4]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\subfigure[image5]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\subfigure[image6]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\caption{Fasi del processo di impregnazione}
\label{fig:images}
\end{figure}
\end{document}
替换\fbox{\hbox to 5pc{\vbox to 5pc{~}}}
为\includegraphics{...}
。如果您需要 3x2,则\\
在第二个 之后给出\subfigure
。现在是 2x3。