防止标题中空格增多

防止标题中空格增多

我正在将我的论文写成一系列,这些论文有相当严格的指导方针,例如章节标题前后的间距。第一级标题(即章节)前后应该有两行空白行,第二级标题(即节)前后应该有两行空白行,第三级标题(即小节)前后应该有一行空白行。但是,如果前一个高级标题下方有一个低级标题,则应该隐藏低级标题之前的空白行。我似乎找不到使用 titlesec 包执行此操作的方法。下面的 MWE。

\documentclass[a4paper]{report}
\usepackage{titlesec}

\titlespacing{\chapter}{0pt}{2\baselineskip}{2\baselineskip}
\titlespacing{\section}{0pt}{2\baselineskip}{\baselineskip}
\titlespacing{\subsection}{0pt}{\baselineskip}{\baselineskip}
\begin{document}
\chapter{First chapter}
\section{First section of the first chapter}
Text text text
\chapter{Second chapter}
Text text text
\section{First section of the second chapter}
Text text text
\end{document}

在这种情况下,第一节标题的前导垂直空间过多,即 4 个空白行,而它应该只有章节标题规定的两个空白行。如果当前标题直接位于更高级别标题下方,我该如何隐藏之前的空白行?

答案1

我认为这应该接近要求。我不知道章节标题应该如何格式化,所以你可能必须调整它。此外,你可能还必须微调测量值。请注意,如果\titlespacing{\chapter}没有该命令,该命令将不会产生任何效果\titleformat{chapter}

\titleformat{\chapter}[display]{\Huge\bfseries}{\huge Chapter \thechapter}{1ex}{}
\titlespacing{\chapter}{0pt}{2\baselineskip}{1.5\baselineskip}
\titlespacing{\section}{0pt}{\baselineskip}{\baselineskip}
\titlespacing{\subsection}{0pt}{\baselineskip}{\baselineskip}

相关内容