同时指定标题行和章节名称之间以及一个章节结尾和另一个章节开头之间的距离的最佳方法

同时指定标题行和章节名称之间以及一个章节结尾和另一个章节开头之间的距离的最佳方法

我有一些包含标题行的文档,并且我还指定了章节可以在同一页开始

以下是最小化的示例:

% !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可以同时调整所有章节。

当然,你必须为beforeafter分离选择好的价值观。

例如\titlespacing*{\chapter}{0pt}{-3ex}{-3ex}工作正常。

如果您更改主文本字体大小(例如从 10pt 更改为 12pt),使用ex单位将保持比例。

b

% !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 命令。

相关内容