这是我的代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}[htbp]
\subfloat[Distribution of herring in 2018]{
\begin{minipage}[c][1\width]{
0.2\textwidth}
% \centering
\includegraphics[width=3cm,height=3cm]{hp2018.png}
\end{minipage}}
\hfill
\subfloat[Distribution of herring in 2019]{
\begin{minipage}[c][1\width]{
0.2\textwidth}
% \centering
\includegraphics[width=3cm,height=3cm]{hp2019.png}
\end{minipage}}
\hfill
\subfloat[Distribution of herring in 2020]{
\begin{minipage}[c][1\width]{
0.2\textwidth}
% \centering
\includegraphics[width=3cm,height=3cm]{hp2020.png}
\end{minipage}}
\hfill
\subfloat[Distribution of herring in 2021]{
\begin{minipage}[c][1\width]{
0.2\textwidth}
% \centering
\includegraphics[width=3cm,height=3cm]{hp2021.png}
\end{minipage}}
\hfill
\subfloat[Distribution of mackere in 2016]{
\begin{minipage}[c][1\width]{
0.2\textwidth}
% \centering
\includegraphics[width=3cm,height=3cm]{mp2018.png}
\end{minipage}}
\hfill
\subfloat[Distribution of mackere in 2019]{
\begin{minipage}[c][1\width]{
0.2\textwidth}
% \centering
\includegraphics[width=3cm,height=3cm]{mp2019.png}
\end{minipage}}
\hfill
\subfloat[Distribution of mackere in 2020]{
\begin{minipage}[][1\width]{
0.2\textwidth}
% \centering
\includegraphics[width=3cm,height=3cm]{mp2020.png}
\end{minipage}}
\caption{Predicter distribution of herring and mackere in 2018-2021}\label{18-21}
\end{figure}
\end{document}
第二行的图形没有居中,如何让它们集中到一起或者让它们位于第一行图形的正下方?
答案1
如果您希望第二行中的子图在第一行中的子图下方对齐,请不要使用\hfill
作为分隔符。如果您0.22\textwidth
为子图分配相对宽度,那么0.04\texwidth
第一行中的三个空白实例中的每一个都会留下;因此,\hfill
用替换hspace*{0.04\textwidth}
,您就大功告成了。(4*0.22+3*0.04=1
。)
不过,请在前四个子图后留一个空行,以强制 LaTeX 插入显式换行符。我进一步建议您不要在 的参数中为图像指定固定的宽度和高度\includegraphics
。相反,使用相对尺寸例如\textwidth
。
\documentclass{article}
\usepackage[demo]{graphicx} % remove 'demo' option in real document
\usepackage{subfig}
\begin{document}
\begin{figure}[htbp]
\subfloat[Distribution of herring in 2018]{%
\begin{minipage}[t]{0.22\textwidth}
\includegraphics[width=\textwidth]{hp2018}
\end{minipage}}
\hspace*{0.04\textwidth}%
\subfloat[Distribution of herring in 2019]{%
\begin{minipage}[t]{0.22\textwidth}
\includegraphics[width=\textwidth]{hp2019}
\end{minipage}}
\hspace*{0.04\textwidth}%
\subfloat[Distribution of herring in 2020]{%
\begin{minipage}[t]{0.22\textwidth}
\includegraphics[width=\textwidth]{hp2020}
\end{minipage}}
\hspace*{0.04\textwidth}%
\subfloat[Distribution of herring in 2021]{%
\begin{minipage}[t]{0.22\textwidth}
\includegraphics[width=\textwidth]{hp2021}
\end{minipage}}
% Insert a blank line to force a line break:
\subfloat[Distribution of mackerel in 2016]{%
\begin{minipage}[t]{0.22\textwidth}
\includegraphics[width=\textwidth]{mp2018}
\end{minipage}}
\hspace*{0.04\textwidth}%
\subfloat[Distribution of mackerel in 2019]{%
\begin{minipage}[t]{0.22\textwidth}
\includegraphics[width=\textwidth]{mp2019}
\end{minipage}}
\hspace*{0.04\textwidth}%
\subfloat[Distribution of mackerel in 2020]{%
\begin{minipage}[t]{0.22\textwidth}
\includegraphics[width=\textwidth]{mp2020}
\end{minipage}}
\caption{Predictor distribution of herring and mackerel in 2018--2021}\label{18-21}
\end{figure}
\end{document}
答案2
我将使用包subfigure
中定义的环境subcaption
,删除minipage
s 和subfloat
s:
编辑:
对于图像宽度,现在考虑@Mico 在其评论中的建议。\setkeys{Gin}{width=\linewidth}
选择适当的subfigure
s 宽度后,图形将保持在文本宽度内。
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage[font=small]{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}[htbp]
\setkeys{Gin}{width=\linewidth}
\begin{subfigure}[b]{0.22\textwidth}
\includegraphics{hp2018.png}
\caption{Distribution of herring in 2018}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.22\textwidth}
\includegraphics{hp2019.png}
\caption{Distribution of herring in 2019}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.22\textwidth}
\includegraphics{hp2020.png}
\caption{Distribution of herring in 2020}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.22\textwidth}
\includegraphics{hp2021.png}
\caption{Distribution of herring in 2021}
\end{subfigure}
\medskip
\begin{subfigure}[b]{0.22\textwidth}
\includegraphics{mp2018.png}
\caption{Distribution of mackere in 2016}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.22\textwidth}
\includegraphics{mp2019.png}
\caption{Distribution of mackere in 2019}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.22\textwidth}
\includegraphics{mp2020.png}
\caption{Distribution of mackere in 2020}
\end{subfigure}
\caption{Predicter distribution of herring and mackere in 2018-2021}\label{18-21}
\end{figure}
\end{document}