![同时指定标题行和章节名称之间以及一个章节结尾和另一个章节开头之间的距离的最佳方法](https://linux22.com/image/440976/%E5%90%8C%E6%97%B6%E6%8C%87%E5%AE%9A%E6%A0%87%E9%A2%98%E8%A1%8C%E5%92%8C%E7%AB%A0%E8%8A%82%E5%90%8D%E7%A7%B0%E4%B9%8B%E9%97%B4%E4%BB%A5%E5%8F%8A%E4%B8%80%E4%B8%AA%E7%AB%A0%E8%8A%82%E7%BB%93%E5%B0%BE%E5%92%8C%E5%8F%A6%E4%B8%80%E4%B8%AA%E7%AB%A0%E8%8A%82%E5%BC%80%E5%A4%B4%E4%B9%8B%E9%97%B4%E7%9A%84%E8%B7%9D%E7%A6%BB%E7%9A%84%E6%9C%80%E4%BD%B3%E6%96%B9%E6%B3%95.png)
我有一些包含标题行的文档,并且我还指定了章节可以在同一页开始
以下是最小化的示例:
% !TeX program = xelatex
\documentclass[10pt,a4paper,twoside]{report}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,250mm},
outer=15mm,
inner=20mm,
top=15mm,
}
\setlength{\parindent}{0em}
\setlength{\parskip}{1em}
% to specify chapter titles
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{5pt}{\LARGE}
\titlespacing*{\chapter}{0pt}{0pt}{0pt}
\raggedbottom
\usepackage{lipsum}
\titleformat{\chapter}[display]
{\normalfont\bfseries}{}{0pt}{\Large}
\titleformat{\chapter}[hang]{\LARGE\bfseries}{\thechapter{. }}{0pt}{\LARGE\bfseries}
% to specify headers
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{plain}{\fancyhf{}\renewcommand{\headrulewidth}{1pt}
\fancyhead[RE,LO]{}
\fancyfoot[LE,RO]{}
\fancyfoot[RE,LO]{\jobname}}
% to specify that chapters are on same page
\usepackage{etoolbox}
\makeatletter
\patchcmd\chapter
{\if@openright\cleardoublepage\else\clearpage\fi}
{\par}
{}{}
\makeatother
\begin{document}
\chapter{INTRODUCTION}
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
\chapter{FIRST CHAPTER}
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
\end{document}
使用此代码,我得到这个
但是,我想减少标题行和章节开头之间的距离。这可以通过更改来实现
\titlespacing*{\chapter}{0pt}{0pt}{0pt}
例如,
\titlespacing*{\chapter}{0pt}{-20pt}{0pt}
但是,如果我这样做,我会得到以下结果:
如您所见,我得到了一个章节的结尾和另一个章节的开头之间的重叠,这是我不想要的。在这个特定的例子中,我可以通过在 \chapter{FIRST CHAPTER} 之前插入 \vspace{0.5cm}(或任何其他所需的数字)来消除这种情况,但我想要一个更通用的解决方案(我不想单独为每个章节执行此操作,而是同时为所有章节执行此操作)。
实现这一目标的最佳方法是什么?
答案1
您\titlespacing
可以同时调整所有章节。
当然,你必须为before
和after
分离选择好的价值观。
例如\titlespacing*{\chapter}{0pt}{-3ex}{-3ex}
工作正常。
如果您更改主文本字体大小(例如从 10pt 更改为 12pt),使用ex
单位将保持比例。
% !TeX program = xelatex
\documentclass[10pt,a4paper,twoside]{report}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,250mm},
outer=15mm,
inner=20mm,
top=15mm,
}
\usepackage{lipsum}
\setlength{\parindent}{0em}
\setlength{\parskip}{1em}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\LARGE\bfseries}{\thechapter{. }}{0pt}{\LARGE\bfseries}
\titlespacing*{\chapter}{0pt}{-3ex}{-3ex}% changed <<<<<<<<<<<<<<<<<<<<<<
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{plain}{\fancyhf{}\renewcommand{\headrulewidth}{1pt}
\fancyhead[RE,LO]{}
\fancyfoot[LE,RO]{}
\fancyfoot[RE,LO]{\jobname}}
\usepackage{etoolbox}
\makeatletter
\patchcmd\chapter
{\if@openright\cleardoublepage\else\clearpage\fi}
{\par}
{}{}
\makeatother
\raggedbottom
\begin{document}
\chapter{INTRODUCTION}
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
\chapter{FIRST CHAPTER}
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
\chapter{SECOND CHAPTER}
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
\chapter{THIRD CHAPTER}
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
\chapter{FOURTH CHAPTER}
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
Some text
\end{document}
答案2
看到这个问题后自定义 \chapter 定义,我决定将章节命令重新定义为
\makeatletter
\let\stdchapter\chapter
\renewcommand*\chapter{%
\@ifstar{\starchapter}{\@dblarg\nostarchapter}}
\newcommand*\starchapter[1]{\vspace{0.85cm}\stdchapter*{#1}}
\def\nostarchapter[#1]#2{\vspace{0.85cm}\stdchapter[{#1}]{#2}}
\makeatother
换句话说,新的 \chapter 命令包含 \vspace 和旧的 \chapter 命令。