使用全尺寸的子浮动会导致它们向右移动

使用全尺寸的子浮动会导致它们向右移动

我快疯了。我对 LaTeX 的了解已经到了极限,在网上找不到任何线索。所以如果能提供一些意见,我将不胜感激!

问题
当使用subfloats(与subfig软件包一起)将图形包含在完整文本/列宽中时,图形似乎会稍微向右移动,延伸到文本区域之外。
我第一次注意到这一点是在准备一份双栏手稿时,我需要两个带有副标题的图形。

以下是一个例子:

\documentclass{article}

\usepackage{graphicx}
\usepackage{subfig}
\usepackage{blindtext}

\begin{document}

\begin{figure}
    \centering
    \includegraphics[width=\textwidth,height=0.1\textwidth]{dummy.pdf}
    \caption{Caption 1}
\end{figure}

\begin{figure}
    \centering
    \subfloat[Subcaption 2a.]{
        \includegraphics[width=\textwidth,height=0.1\textwidth]{dummy.pdf}
    }\\
    \subfloat[Subcaption 2b.]{
        \includegraphics[width=\textwidth,height=0.1\textwidth]{dummy.pdf}
    }
    \caption{Caption 2}
\end{figure}

\blindtext

\end{document}

(使用width=\columnwidthwidth=\linewidth会导致相同的行为。)

请注意,使用较小的宽度(例如)时不会发生这种情况width=0.9\textwidth。然后,一切都正常。

问题
我怎样才能以合理的方式解决这个问题?

我当然可以减小子浮动图形的宽度。但我对一致性很执着,我的图形基本上只显示相同的内容,只有细微的变化,因此当尺寸突然改变时,这一点会很明显。我还想避免重新缩放所有图形,如果它们跨越整个文本/列宽度,我会更喜欢。

答案1

在包含图像之前,您在左括号后引入了一些虚假的空白。

它应该是:

% arara: pdflatex

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\usepackage{blindtext}

\begin{document}    
\begin{figure}
    \centering
    \includegraphics[width=\textwidth,height=0.1\textwidth]{dummy.pdf}
    \caption{Caption \thefigure}
\end{figure}    
\begin{figure}
    \subfloat[Subcaption \thefigure a.]{%
        \includegraphics[width=\linewidth,height=0.1\textwidth]{dummy.pdf}
        }

    \subfloat[Subcaption \thefigure b.]{%
        \includegraphics[width=\linewidth,height=0.1\textwidth]{dummy.pdf}
        }
    \caption{Caption \thefigure}
\end{figure}    
\blindtext  
\end{document}

在此处输入图片描述

请注意,设置图像的宽度和高度并不是一个好主意,因为您可能会扭曲图形。只需设置宽度并将图像裁剪为所需的高度。我将其留在上面的代码中,因为在使用选项的情况下它非常[demo]实用graphicx

如果你也想设置高度,请查看这个帖子

相关内容