章节标题后的垂直空间太多

章节标题后的垂直空间太多

在一个書類文档(由于某种原因,文章类的问题没有出现)我需要插入一个只包含图像的部分(图片库)。图像的大小和纵横比各不相同,但有些代码有助于自动调整它们的大小。根据图像的不同,部分标题后的垂直空间可能太大。我猜问题是部分标题后的空间被拉得太长,以避免页面末尾出现空白。我尝试增加标题前和“行”(如果我可以这样称呼它们)之间的垂直空间,但没有成功。

这是 MWE。如何增加标题前和行之间的垂直空间?我正在寻找一个通用的解决方案,而不是针对特定的图像组合进行定制。

提前感谢任何线索。

PS 我的实际文档是用 XeLaTex 编译的,我希望这不会影响解决方案。

\documentclass{book}
\usepackage{mwe}
\usepackage{xfp}
% add to \includegraphics the option sqrtofarea that sizes image so that it has a given area, regardless of aspect ratio
\makeatletter
\define@key{Gin}{sqrtofarea}{%
    \def\Gin@req@sizes{%
      \edef\Gin@scalex{\fpeval{#1/sqrt(\Gin@nat@height*\Gin@nat@width)}}%
      \let\Gin@scaley\Gin@exclamation
      \Gin@req@height\Gin@scalex\Gin@nat@height
      \Gin@req@width\Gin@scalex\Gin@nat@width
      }%
  \@tempswatrue}
\makeatother

% command helping to insert images in a photo gallery
%usage: \imageofgallery{image file}{square root of image area}{margins of image}
\newcommand{\imageofgallery}[3]{%
\begingroup\setlength{\fboxrule}{0pt}\setlength{\fboxsep}{#3}\setbox0=\hbox{\fbox{\includegraphics[sqrtofarea=#2]{#1}}}\parbox{\wd0}{\box0}\endgroup\hspace{1pt}%
}

\begin{document}
\section{Image gallery}
\begin{center}
\newcommand{\imgsize}{12em} % images will be sized so they have an area of 12x12 sq-em, regardless of aspect ratio
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image-1x1}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\end{center}
\end{document}

在此处输入图片描述

答案1

给定代码的主要问题是底部图片不适合并被移动到下一页。

\raggedbottom环境持续时间的问题center\clearpage最后以 结尾。

\documentclass{book}
\usepackage{mwe}
\usepackage{xfp}
% add to \includegraphics the option sqrtofarea that sizes image
% so that it has a given area, regardless of aspect ratio
\makeatletter
\define@key{Gin}{sqrtofarea}{%
    \def\Gin@req@sizes{%
      \edef\Gin@scalex{\fpeval{#1/sqrt(\Gin@nat@height*\Gin@nat@width)}}%
      \let\Gin@scaley\Gin@exclamation
      \Gin@req@height\Gin@scalex\Gin@nat@height
      \Gin@req@width\Gin@scalex\Gin@nat@width
      }%
  \@tempswatrue}
\makeatother

% command helping to insert images in a photo gallery
%usage: \imageofgallery{image file}{square root of image area}{margins of image}
\newcommand{\imageofgallery}[3]{%
  \begingroup
  \setlength{\fboxrule}{0pt}%
  \setlength{\fboxsep}{#3}%
  \sbox0{\fbox{\includegraphics[sqrtofarea=#2]{#1}}}%
  \parbox{\wd0}{\box0}%
  \endgroup
  \linebreak[0]%
}

\begin{document}

\section{Image gallery}
\begin{center}
\raggedbottom % this is local to center
\newcommand{\imgsize}{12em} % images will be sized so they have an area of 12x12 sq-em, regardless of aspect ratio
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image-1x1}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image-1x1}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image-1x1}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image-1x1}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image-1x1}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\imageofgallery{example-image-1x1}{\imgsize}{1ex}
\imageofgallery{example-image}{\imgsize}{1ex}
\imageofgallery{example-image-16x9}{\imgsize}{1ex}
\imageofgallery{example-image-10x16}{\imgsize}{1ex}
\clearpage
\end{center}

\end{document}

我对代码做了一些小改动:\setbox0=\hbox应该是\sbox0;而不是\hspace{1pt}使用\linebreak[0],因此不会插入额外的空格,但是仍然允许在每个图像后换行。

在此处输入图片描述

相关内容