我试图对齐图像,如下图所示。我是 Latex 新手,需要帮助
\usepackage{graphicx} % takes care of graphic including machinery
\usepackage[section]{placeins}
\usepackage{subfigure}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{float}
\usepackage[table]{xcolor}
\usepackage[skip=1ex]{caption}
\section{Experiments}
\begin{figure}[H]
\centering
%\begin{tabular}{ccccc}
\subfigure[]{
\includegraphics[width=3cm, height = 3cm]{real_data/st.png}}
\subfigure[]{
\includegraphics[width=3cm, height = 3cm]{real_data/dta.png}}
\subfigure[]{
\includegraphics[width=3cm, height = 3cm]{real_data/e.png}}
\subfigure[]{
\includegraphics[width=3cm, height = 3cm]{real_data/ot.png}}\\
\subfigure[]{
\includegraphics[width=3cm, height = 3cm]{real_data/ge_30.png}}
\subfigure[]{
\includegraphics[width=3cm, height = 3cm]{real_data/ge_30.png}}
\subfigure[]{
\includegraphics[width=3cm, height = 3cm]{real_data/e_30.png}}
\subfigure[]{
\includegraphics[width=3cm, height = 3cm]{real_data/30.png}}
\end{figure}
答案1
\documentclass
请始终提供完整的 MWE(最小工作示例),即以 开头并以 结尾的小型但完整的文档\end{document}
。目前尚不清楚您文档的页面布局。- 您的代码片段仅包含 8 张图片,但问题中您展示了 10 张图片(因此在下面的 MWE 中我重复了其中的最后两张。
- 由于所有图像都有相同的大小,因此使用键是非常明智的
Gin
,这使得图形代码显著缩短。 subfigure
是过时的软件包,相反,我使用它subcaption
和环境(它也受3.1 以上版本\subfloat
支持):subcaption
\documentclass{article}
\usepackage{geometry}
\usepackage[demo]{graphicx} % in real document remove "demo"
\usepackage[skip=0.5ex,belowskip=1ex]{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}[ht!]
\centering
\setkeys{Gin}{width=3cm, height = 3cm}
\subfloat[]{\includegraphics{real_data/st.png}}
\quad
\subfloat[]{\includegraphics{real_data/dta.png}}
\subfloat[]{\includegraphics{real_data/e.png}}
\quad
\subfloat[]{\includegraphics{real_data/ot.png}}
\quad
\subfloat[]{\includegraphics{real_data/ge_30.png}}
\quad
\subfloat[]{\includegraphics{real_data/ge_30.png}}
\subfloat[]{\includegraphics{real_data/e_30.png}}
\quad
\subfloat[]{\includegraphics{real_data/30.png}}
\quad
\subfloat[]{\includegraphics{real_data/e_30.png}}
\quad
\subfloat[]{\includegraphics{real_data/30.png}}
\caption{My figures}
\end{figure}
\end{document}
答案2
从你问题中的代码来看,我猜你现在使用的是subfigure
包。请记住,此特定包已被视为弃用,应由以下任一包替换:subfig
或者subcaption
包裹。
这里,我提供了两个使用这两个包的示例。这些示例会导致略微不同的对齐方式,尤其是相邻图像之间以及图像与边距之间的水平间距。当然,您可以调整标题位置、间距、图像大小和其他参数以满足您的需求。
(垂直红线表示边距。)
示例 1:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig} % or \usepackage{subcaption}
\usepackage[export]{adjustbox}
\begin{document}
\begin{figure}
\adjustboxset*{width=0.22\columnwidth, valign=c}
\centering
\subfloat[]{\adjincludegraphics{example-image}}\quad
\subfloat[]{\adjincludegraphics{example-image}}\medskip
\subfloat[]{\adjincludegraphics{example-image}}\quad
\subfloat[]{\adjincludegraphics{example-image}}\quad
\subfloat[]{\adjincludegraphics{example-image}}\quad
\subfloat[]{\adjincludegraphics{example-image}}\medskip
\subfloat[]{\adjincludegraphics{example-image}}\quad
\subfloat[]{\adjincludegraphics{example-image}}\quad
\subfloat[]{\adjincludegraphics{example-image}}\quad
\subfloat[]{\adjincludegraphics{example-image}}
\caption{picture}
\label{fig:key}
\end{figure}
\end{document}
示例 2:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\hspace{0.225\textwidth}
\hfill
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\hfill
\hspace{0.225\textwidth}
\medskip
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\medskip
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.225\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image}
\caption{}
\end{subfigure}
\caption{figure caption text goes here}
\label{fig:key}
\end{figure}
\end{document}