这两个 LaTeX 片段仅在子图 1 末尾的 '%' 符号上有所不同,但它们产生的子图对齐方式不同:
片段 1(不含“%”符号):
\begin{figure*}
\centering
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1a_line.pdf}
\caption{Subfigure 1}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1a_region.png}
\caption{Subfigure 2}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1b_line.pdf}
\caption{Subfigure 3}
\end{subfigure}
\hspace{0mm}
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1a_region.png}
\caption{Subfigure 4}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1c_line.pdf}
\caption{Subfigure 5}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1c_region.png}
\caption{Subfigure 6}
\end{subfigure}
% \caption{Stability analysis of example \ref{example:compound}}
\caption{Hello}
\end{figure*}
片段 1(带有'%'符号):
\begin{figure*}
\centering
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1a_line.pdf}
\caption{Subfigure 1}
\end{subfigure}%
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1a_region.png}
\caption{Subfigure 2}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1b_line.pdf}
\caption{Subfigure 3}
\end{subfigure}
\hspace{0mm}
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1a_region.png}
\caption{Subfigure 4}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1c_line.pdf}
\caption{Subfigure 5}
\end{subfigure}
\begin{subfigure}[b]{0.33\textwidth}
\centering
\includegraphics[width=\textwidth]{example1c_region.png}
\caption{Subfigure 6}
\end{subfigure}
% \caption{Stability analysis of example \ref{example:compound}}
\caption{Hello}
\end{figure*}
为什么“%”符号会影响子图的位置?
答案1
一些一般性评论:
\centering
每个环境的7条指令figure*
没有任何用处;请删除它们。OP 的第一个
figure*
环境每行仅显示两个子图,而不是三个。这是因为每个子图后面的隐式空格\end{subfigure}
被允许保留。在 OP 的第二个环境中情况并非如此figure*
。
无论如何,我认为您的浮动真正需要的是每行一些位置合适的\hfill
指令,以及相对子图宽度的轻微减少,从0.33\textwidth
到0.32\textwith
。
\documentclass[twocolumn,demo]{article} % remove 'demo' option in real document
\usepackage{graphicx,subcaption}
\begin{document}
\begin{figure*}
\captionsetup[subfigure]{skip=0.25\baselineskip}
\begin{subfigure}[b]{0.32\textwidth}
\includegraphics[width=\textwidth]{example1a_line.pdf}
\caption{Subfigure 1}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.32\textwidth}
\includegraphics[width=\textwidth]{example1a_region.png}
\caption{Subfigure 2}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.32\textwidth}
\includegraphics[width=\textwidth]{example1b_line.pdf}
\caption{Subfigure 3}
\end{subfigure} % keep the next line blank to force a line-break
\medskip
\begin{subfigure}[b]{0.32\textwidth}
\includegraphics[width=\textwidth]{example1a_region.png}
\caption{Subfigure 4}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.32\textwidth}
\includegraphics[width=\textwidth]{example1c_line.pdf}
\caption{Subfigure 5}
\end{subfigure}\hfill
\begin{subfigure}[b]{0.32\textwidth}
\includegraphics[width=\textwidth]{example1c_region.png}
\caption{Subfigure 6}
\end{subfigure}
\caption{Stability analysis}
\label{example:compound}
\end{figure*}
\end{document}
答案2
尝试这个:
\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure*}
\centering
\begin{subfigure}[b]{0.325\textwidth}
\centering
\includegraphics[width=\linewidth]{a.png}
\caption{Subfigure 1}
\end{subfigure}
\begin{subfigure}[b]{0.325\textwidth}
\centering
\includegraphics[width=\linewidth]{a.png}
\caption{Subfigure 2}
\end{subfigure}
\begin{subfigure}[b]{0.325\textwidth}
\centering
\includegraphics[width=\linewidth]{a.png}
\caption{Subfigure 3}
\end{subfigure}
\vskip\floatsep
\begin{subfigure}[b]{0.325\textwidth}
\centering
\includegraphics[width=\linewidth]{a.png}
\caption{Subfigure 4}
\end{subfigure}
\begin{subfigure}[b]{0.325\textwidth}
\centering
\includegraphics[width=\linewidth]{a.png}
\caption{Subfigure 5}
\end{subfigure}
\begin{subfigure}[b]{0.325\textwidth}
\centering
\includegraphics[width=\linewidth]{a.png}
\caption{Subfigure 6}
\end{subfigure}
% \caption{Stability analysis of example \ref{example:compound}}
\caption{Hello}
\end{figure*}
\end{document}