尽管子图宽度和水平间距都增加了,为什么使用\hspace*
而不是时输出会有差异?\hspace
\textwidth
\documentclass{article}
\usepackage{subcaption,mwe}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\end{subfigure}%
\hspace{0.05\textwidth}
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\end{subfigure}%
\hspace{0.05\textwidth}
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\end{subfigure}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\end{subfigure}%
\hspace*{0.05\textwidth}
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\end{subfigure}%
\hspace*{0.05\textwidth}
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\end{subfigure}
\end{figure}
\end{document}
答案1
图像行对于行来说太宽。\hspace
引入断点,因此行在 B 之后断点,并且下一行开头的空格被丢弃。
由于\hspace*
不允许换行,所以它们会一直占一行,导致行满
Overfull \hbox (4.44969pt too wide) in paragraph at lines 21--32
由于在 后添加了单词空格,所以它过于饱满\hspace
。
\documentclass{article}
\usepackage{subcaption,mwe}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\end{subfigure}%
\hspace{0.049\textwidth}%
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\end{subfigure}%
\hspace{0.049\textwidth}%
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\end{subfigure}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-a}
\end{subfigure}%
\hspace*{0.05\textwidth}%
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-b}
\end{subfigure}%
\hspace*{0.05\textwidth}%
\begin{subfigure}[t]{0.3\textwidth}
\includegraphics[width=\linewidth]{example-image-c}
\end{subfigure}
\end{figure}
\end{document}
注意,\hspace{0.05\textwidth}
舍入误差会使它稍微过满,所以我不得不稍微减少它。在实践中,最好不要使用这种固定长度,而只\hfill
在图像之间使用,这将扩大图像之间的距离,而不必担心舍入误差。