我有 6 个图形,将它们放在两行中(每行 3 个子图形)。子图形之间(每行)有水平空白。我将使用这些空格使子图形尽可能大(同时保持其纵横比)。我的代码如下,
\documentclass[conference]{IEEEtran}
\usepackage{algorithm, algpseudocode, dsfont, color, soul, tikz, amsmath, amssymb, amsfonts, amsthm, bbm, bbold, fixmath, mathtools, multirow, boldline, xcolor, colortbl, url, footnote, cite}
\begin{document}
\begin{figure*}
\begin{subfigure}[t]{0.33\linewidth}
\includegraphics[width=\linewidth, height=\textheight, keepaspectratio]{x2_RWD.pdf}
\end{subfigure}
\begin{subfigure}[t]{0.33\linewidth}
\includegraphics[width=\linewidth, height=\textheight, keepaspectratio]{x4_RWD.pdf}
\end{subfigure}
\begin{subfigure}[t]{0.33\linewidth}
\includegraphics[width=\linewidth, height=\textheight, keepaspectratio]{x7_RWD.pdf}
\end{subfigure}
\begin{subfigure}[t]{0.33\linewidth}
\includegraphics[width=\linewidth, height=\textheight, keepaspectratio]{x2_NRD.pdf}
\end{subfigure}
\begin{subfigure}[t]{0.33\linewidth}
\includegraphics[width=\linewidth, height=\textheight, keepaspectratio]{x4_NRD.pdf}
\end{subfigure}
\begin{subfigure}[t]{0.33\linewidth}
\includegraphics[width=\linewidth, height=\textheight, keepaspectratio]{x7_NRD.pdf}
\end{subfigure}
\end{figure*}
\end{document}
答案1
由于您没有利用subfigure
环境的任何特殊功能 - 例如设置标题和插入标签以进行交叉引用的功能,因此您不妨使用普通minipage
环境。
(在下面的代码中,如果您确实需要提供\caption
和\label
语句,只需将\begin{minipage}
和的所有实例分别改\end{minipage}
回\begin{subfigure}
和\end{subfigure}
。当然,一定要加载subcaption
包。)
为了最大限度地增加相邻图形之间可能的水平分离,在/环境之间插入\hfill
(或\hspace{\fill}
) 指令。minipage
subcaption
\documentclass[twocolumn]{article}
\usepackage[demo]{graphicx} % omit 'demo' option in real doc.
\begin{document}
\begin{figure*}
\begin{minipage}[t]{0.325\linewidth}
\includegraphics[width=\linewidth]{x2_RWD.pdf}
\end{minipage}\hfill
\begin{minipage}[t]{0.325\linewidth}
\includegraphics[width=\linewidth]{x4_RWD.pdf}
\end{minipage}\hfill
\begin{minipage}[t]{0.325\linewidth}
\includegraphics[width=\linewidth]{x7_RWD.pdf}
\end{minipage}
%% leaving a blank line is deliberate, to tell TeX that a line break needs to occur
\medskip
\begin{minipage}[t]{0.325\linewidth}
\includegraphics[width=\linewidth]{x2_NRD.pdf}
\end{minipage}\hfill
\begin{minipage}[t]{0.325\linewidth}
\includegraphics[width=\linewidth]{x4_NRD.pdf}
\end{minipage}\hfill
\begin{minipage}[t]{0.325\linewidth}
\includegraphics[width=\linewidth]{x7_NRD.pdf}
\end{minipage}
\end{figure*}
\end{document}
附录,在 OP 提供了关于他/她使用的文档类和包的附加信息后发布。关于这些包:(a)fixmath
仅在使用 Computer Modern 字体时才应加载 - 此处并非如此。(b) 和不应xcolor
独立colortbl
加载。(c) 您加载的某些包会自动加载其他一些包;因此,无需明确加载color
、amsmath
和amsfonts
包。(d) 由于所有图形都具有相同的高度,因此[t]
可以从设置中省略位置说明符subcaption
。
\documentclass[conference,demo]{IEEEtran} % omit 'demo' option in real doc.
\usepackage[table]{xcolor} % don't load 'colortbl' and 'xcolor' independently from each other
\usepackage[hyphens]{url} % no need to load 'url' without 'hyphens' option
\usepackage{algorithm, algpseudocode, soul,
tikz, mathtools, amssymb, amsthm,
multirow, footnote, cite, subcaption,
dsfont, bbm, bbold, boldline}
%% 'fixmath' should only be used if Computer Modern
%% fonts are in use -- which is not the case here
\begin{document}
\begin{figure*}
\begin{subfigure}{0.325\linewidth}
\includegraphics[width=\linewidth]{x2_RWD.pdf}
\caption{\dots} \label{fig:a}
\end{subfigure}\hfill
\begin{subfigure}{0.325\linewidth}
\includegraphics[width=\linewidth]{x4_RWD.pdf}
\caption{\dots} \label{fig:b}
\end{subfigure}\hfill
\begin{subfigure}{0.325\linewidth}
\includegraphics[width=\linewidth]{x7_RWD.pdf}
\caption{\dots} \label{fig:c}
\end{subfigure}
%% Leaving a blank line is deliberate, to tell
%% LaTeX that a line break needs to occur
\medskip
\begin{subfigure}{0.325\linewidth}
\includegraphics[width=\linewidth]{x2_NRD.pdf}
\caption{\dots} \label{fig:d}
\end{subfigure}\hfill
\begin{subfigure}{0.325\linewidth}
\includegraphics[width=\linewidth]{x4_NRD.pdf}
\caption{\dots} \label{fig:e}
\end{subfigure}\hfill
\begin{subfigure}{0.325\linewidth}
\includegraphics[width=\linewidth]{x7_NRD.pdf}
\caption{\dots} \label{fig:f}
\end{subfigure}
\caption{Overall figure caption}
\label{fig:overall}
\end{figure*}
\end{document}
答案2
您不需要任何subfigure
环境,除非您想要子字幕。
这里的图像在水平和垂直方向上由相同的白色空间分隔\lineskip
。
\documentclass[twocolumn]{article}
\usepackage[demo]{graphicx} % demo because I don't have your files
\usepackage{lipsum} % for mock text
\newlength{\maxfigurewidth}
\begin{document}
\lipsum[1-3]
\begin{figure*}
\setlength{\maxfigurewidth}{\dimexpr(\textwidth-2\lineskip)/3}
\includegraphics[width=\maxfigurewidth]{x2_RWD.pdf}\hfil
\includegraphics[width=\maxfigurewidth]{x4_RWD.pdf}\hfil
\includegraphics[width=\maxfigurewidth]{x7_RWD.pdf}
\includegraphics[width=\maxfigurewidth]{x2_NRD.pdf}\hfil
\includegraphics[width=\maxfigurewidth]{x4_NRD.pdf}\hfil
\includegraphics[width=\maxfigurewidth]{x7_NRD.pdf}
\caption{Some global caption}\label{whatever}
\end{figure*}
\lipsum[1-12]
\end{document}
自动\lineskip
插入在两行之间,我们手动(用\hfil
)将其插入在列之间。
如果您希望列与列之间或行与行之间没有间距:
\begin{figure*}
\setlength{\maxfigurewidth}{\dimexpr\textwidth/3}
\includegraphics[width=\maxfigurewidth]{x2_RWD.pdf}%
\includegraphics[width=\maxfigurewidth]{x4_RWD.pdf}%
\includegraphics[width=\maxfigurewidth]{x7_RWD.pdf}
\nointerlineskip
\includegraphics[width=\maxfigurewidth]{x2_NRD.pdf}%
\includegraphics[width=\maxfigurewidth]{x4_NRD.pdf}%
\includegraphics[width=\maxfigurewidth]{x7_NRD.pdf}
\caption{Some global caption}\label{whatever}
\end{figure*}
带字幕:
\documentclass[twocolumn]{article}
\usepackage{subcaption}
\usepackage[demo]{graphicx} % demo because I don't have your files
\usepackage{lipsum} % for mock text
\newlength{\maxfigurewidth}
\begin{document}
\lipsum[1-3]
\begin{figure*}
\setlength{\maxfigurewidth}{\dimexpr(\textwidth-2em)/3}
\begin{subfigure}{\maxfigurewidth}
\includegraphics[width=\textwidth]{x2_RWD.pdf}
\caption{one}
\end{subfigure}\hfil
\begin{subfigure}{\maxfigurewidth}
\includegraphics[width=\textwidth]{x4_RWD.pdf}%
\caption{two}
\end{subfigure}\hfil
\begin{subfigure}{\maxfigurewidth}
\includegraphics[width=\textwidth]{x7_RWD.pdf}
\caption{three}
\end{subfigure}
\medskip
\begin{subfigure}{\maxfigurewidth}
\includegraphics[width=\textwidth]{x2_NRD.pdf}%
\caption{four}
\end{subfigure}\hfil
\begin{subfigure}{\maxfigurewidth}
\includegraphics[width=\textwidth]{x4_NRD.pdf}%
\caption{five}
\end{subfigure}\hfil
\begin{subfigure}{\maxfigurewidth}
\includegraphics[width=\textwidth]{x7_NRD.pdf}
\caption{six}
\end{subfigure}
\caption{Some global caption}
\end{figure*}
\lipsum[1-12]
\end{document}