无法增加章节标题前的间距

无法增加章节标题前的间距

我在增加页眉和章节标题之间的间距时遇到了麻烦。根据titlesec软件包文档中的建议,我在序言中添加了以下行:\titlespacing{\section}{0pt}{4em}{3em}。如果我理解正确的话,它应该在章节标题前提供 4em 空间,在章节标题后提供 3em 空间。然而,事实并非如此:标题前的空间明显较小,如您所见:

图片1

我想到了一个不太好的解决方法:如果我\vspace*{0em}在 之前写\section{...},间隙就会增加,但这次肯定是大于 4em:

图片2

目前为止,唯一能以某种方式解决我的问题的方法就是放置类似的东西\vspace*{-40em},但这非常丑陋,我宁愿不这样做。

谷歌搜索并没有起到什么帮助作用。事实上,一些搜索结果显示,人们在减少这个尺寸,但我没有找到太多与我的情况相关的信息。

我在这个例子中使用的代码:

\documentclass[a4paper,14pt]{extarticle}
\usepackage[cm-default]{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage{lipsum}
\usepackage[left=3cm,top=2.5cm,right=1cm,bottom=1.5cm]{geometry}

\usepackage{fancyhdr}
\fancyhead{}
\fancyhead[CH]{header}
\addtolength{\headheight}{\baselineskip}
\fancyfoot{}
\pagestyle{fancy}

\usepackage[compact]{titlesec}
\titleformat{\section}[block]{\filcenter\Large\bfseries}{\thesection}{1ex}{\uppercase}
\titlespacing{\section}{0pt}{4em}{3em}

\begin{document}
    %\vspace*{0pt}
    \section{Lorem ipsum}
    \lipsum[1-3]
\end{document}

我将非常感谢您的任何建议!

答案1

对规格的可能近似值(通常是由对印刷术知之甚少的人做出的,14pt 大小就是明证)如下:

\documentclass[a4paper,14pt]{extarticle}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage[left=3cm,top=2.5cm,right=1cm,bottom=1.5cm,headsep=\baselineskip]{geometry}

\usepackage{fancyhdr}
\fancyhead{}
\fancyhead[C]{header}
\setlength{\headheight}{17pt}
\fancyfoot{}
\pagestyle{fancy}

\usepackage{etoolbox}
\newcommand{\sectionfix}{\newpage\vspace*{3\baselineskip}\nointerlineskip}

\usepackage[compact]{titlesec}
\titleformat{\section}[block]{\filcenter\Large\bfseries}{\thesection}{1ex}{\MakeUppercase}
\titlespacing{\section}{0pt}{0pt}{3em}

\preto{\section}{\sectionfix} % sections start a new page

\begin{document}
    \section{Lorem ipsum}
    \lipsum[1]
    \section{Lorem ipsum}
    \lipsum[1]
\end{document}

请注意,\MakeUppercase比 更好\uppercase;包xunicode由 自动加载fontspec,而不像xltxtra以前那样需要也不推荐(但你如果需要,请加载它)。

在此处输入图片描述

答案2

根据@Kona-chan 和@egreg 之间的讨论,尤其是修辞:

我可以\vspace*{-\headsep}在每个部分之前写一些类似的内容,但我觉得它看起来很丑——或者这样完全没问题吗?

我认为您可能想要执行的操作类似于\renewcommand{\headsep}{1pt}after \begin{document}。这将更改开始新页面的所有部分。

我同意 @egreg 的观点,它看起来没什么吸引力。但规格就是规格。

相关内容