我该如何解决由几何边距选项引起的图形边距问题?

我该如何解决由几何边距选项引起的图形边距问题?

标题边距问题

\documentclass{article}
\usepackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2cm]{geometry}
\usepackage[demo]{graphicx}
\usepackage{tikz}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}

\begin{figure}
\centering
\renewcommand{\arraystretch}{3}
\begin{tabular*}{\textwidth}{@{}ccc@{}}
  \includegraphics[width=0.31\linewidth,height=2cm]{dummy} &
        \includegraphics[width=0.31\linewidth,height=2cm]{dummy}&
        \includegraphics[width=0.31\linewidth,height=2cm]{dummy}\\
    \includegraphics[width=0.31\linewidth,height=2cm]{dummy} &
        \includegraphics[width=0.31\linewidth,height=2cm]{dummy}&
        \includegraphics[width=0.31\linewidth,height=2cm]{dummy}
\end{tabular*}
\caption{\emph{Title.} \blindtext}
\label{fig:mipLevels}
\end{figure}

\end{document}

由于某种原因,geometry包装选项会导致我在上图中突出显示的差距。

(我用它@{}来消除环境左右两侧的间距tabular*。)

答案1

这与geometry也不适合您对图形的构造。相反,它是底部标题上方的默认空间。此长度由 控制\abovecaptionskip

下面我不再使用固定宽度tabular*,但制作了相同的布局。每幅图像的宽度为0.3333\linewidth-1.3333\tabcolsep。图的第一部分宽度为常规宽度\abovecaptionskip(10pt),而第二部分宽度减少了 50%(至 5pt):

在此处输入图片描述

\documentclass{article}
\usepackage[margin=25mm,bottom=20mm]{geometry}
\usepackage[demo]{graphicx}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}

\begin{figure}
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy} \hfill
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy} \hfill
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy}

  \bigskip

  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy} \hfill
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy} \hfill
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy}
  \caption{\emph{Title.} \blindtext}

  \bigskip
  \hrulefill
  \par\bigskip\bigskip

  \setlength{\abovecaptionskip}{.5\abovecaptionskip}% Reduce \abovecaptionskip by 50%
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy} \hfill
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy} \hfill
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy}

  \bigskip

  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy} \hfill
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy} \hfill
  \includegraphics[width=\dimexpr.3333\linewidth-1.333\tabcolsep,height=2cm]{dummy}
  \caption{\emph{Title.} \blindtext}
\end{figure}

\end{document}

答案2

\arraystretch设置为 3。这意味着支撑框的下降部分也乘以 3。但线条\includegraphics没有下降部分,因此该部分用空白填充。

该示例执行相反的操作,设置\arraystretch为 0,并将垂直间隙明确设置为2\tabcolsep水平间隙(根据您的需要进行调整)。

该示例还计算了图像的宽度,以允许表格占据整个文本宽度。

\documentclass{article}
\usepackage[left=2.5cm,right=2.5cm,top=2.5cm,bottom=2cm]{geometry}
\usepackage[demo]{graphicx}
\usepackage{blindtext}
\begin{document}

\begin{figure}
\centering
\renewcommand{\arraystretch}{0}
\newcommand*{\imgwidth}{%
  \dimexpr(\linewidth-4\tabcolsep)/3\relax
}
\begin{tabular*}{\textwidth}{@{}ccc@{}}
  \includegraphics[width=\imgwidth, height=2cm]{dummy} &
  \includegraphics[width=\imgwidth, height=2cm]{dummy}&
  \includegraphics[width=\imgwidth, height=2cm]{dummy}\\[2\tabcolsep]
  \includegraphics[width=\imgwidth, height=2cm]{dummy} &
  \includegraphics[width=\imgwidth, height=2cm]{dummy}&
  \includegraphics[width=\imgwidth, height=2cm]{dummy}
\end{tabular*}
\caption{\emph{Title.} \blindtext}
\label{fig:mipLevels}
\end{figure}

\end{document}

结果

相关内容