删除章节标题前的额外垂直空间

删除章节标题前的额外垂直空间

我正在尝试删除书籍类中章节标题前出现的一些多余的空格。我已使用 titlesec 将 space-above 设置为 0pt,但仍然有大约一行的空格(例如,如果我使用 \section 而不是 \chapter,则不会出现)。

该 MWE 显示了该问题,并绘制了几何框架来指示标题的位置:

\documentclass{book}
\usepackage{geometry}
\usepackage{titlesec}

\geometry{showframe}

\titleformat{\chapter}[hang]%
  {\sffamily\Huge}% format applied to label+text
  {\thechapter}%% label
  {0.5em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\titleformat{\section}[hang]%
  {\sffamily\Huge}% format applied to label+text
  {\thesection}%% label
  {0.5em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\titlespacing*{\chapter}{0pt}{0pt}{0pt}
\titlespacing*{\section}{0pt}{0pt}{0pt}

\begin{document}

\chapter{A Chapter}

Notice the white space above the heading.

\newpage

\section{A Section}

But no white space in this case.

\end{document}

答案1

为了使代码不依赖于字体大小,您可以使用依赖于字体的单位。titlesec 恰好定义了这种单位的快捷方式,用于 \titlespacing: *nmeans n ex,如果需要,可以进行微小的拉伸和收缩,以确保所有页面的底部进行测试)。话虽如此,出于美观原因,我不建议在标题下方没有垂直间距

\documentclass{book}
\usepackage[showframe]{geometry}
\usepackage{titlesec}

\geometry{showframe}

\titleformat{\chapter}[hang]%
  {\sffamily\Huge}% format applied to label+text
  {\thechapter}%% label
  {0.5em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\titleformat{\section}[hang]%
  {\sffamily\Huge}% format applied to label+text
  {\thesection}%% label
  {0.5em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\titlespacing*{\chapter}{0pt}{*-3.5}{*0}
\titlespacing*{\section}{0pt}{0pt}{0pt}

\begin{document}

\chapter{Ä \v Chapter}

Notice no white space above the heading.

\newpage

\section{A Section}

But no white space in this case.

\section{A First Section}

\end{document} 

在此处输入图片描述

答案2

在您的代码中,只需将“章节标题间距之前”进一步减少为-ve 值(例如 -20pt):

\titlespacing*{\chapter}{0pt}{-20pt}{0pt}

在此处输入图片描述

相关内容