我正在尝试控制目录中条目之间的垂直间距。具体来说,我需要在主要部分标题之间以及每次更改级别时使用双倍行距,并在同级别的子标题之间使用单倍行距。
\documentclass[10pt,a4paper]{book}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[subfigure]{tocloft} % add nested figures
\usepackage{subfigure}
\renewcommand{\cftchapdotsep}{\cftdotsep} % Give chapters dots too
\renewcommand{\cftchapfont}{\normalfont} % Change to normal font
\renewcommand{\cftchappagefont}{} % Change to normal font
% Center the word 'CONTENTS' over table of contents
\renewcommand{\contentsname}{\hspace*{\fill}\normalfont\normalsize CONTENTS \hspace*{\fill}}
%add page flush right at top of TOC
\renewcommand{\cftaftertoctitle}{%
\\[\baselineskip]\mbox{}\hfill{\normalfont Page}}
% My attempt to contol the spacing using tocloft
\renewcommand{\cftchapafterpnum}{\vspace{\cftbeforechapskip}}
%\renewcommand{\cftsecafterpnum}{\vspace{\cftbeforechapskip}}
\begin{document}
\tableofcontents
\chapter{First Chapter}
\chapter{Second Chapter}
\section{First Section}
\section{Second Section}
\subsection{First Subsection}
\subsection{Second Subsection}
\subsubsection{First Subsubsection}
\subsubsection{Second subsubsection}
\chapter{Third Chapter}
\end{document}
其结果为:
我需要有:
- 第 2.2 节和第 2.2.1 节之间有双倍行距
这邮政看起来相似,但我不明白该命令的作用\renewcommand{\cftchapafterpnum}{\vspace{\cftbeforechapskip}}
。通过简单的试错,我得出结论,该行
\renewcommand{\cftchapafterpnum}{\vspace{\cftbeforechapskip}}
在第 1 章和第 1.1 节之间创建了一个额外的空格,但我不明白为什么
\renewcommand{\cftsecafterpnum}{\vspace{\cftbeforesecskip}}
不会更改生成的文档。我已查看了托克洛夫特,但我似乎不明白为什么更改\cftchapafterpnum
为\cftsecafterpnum
没有效果。我希望我接近了。
提前致谢!
答案1
轻松完成埃托克在“另一种兼容模式”中(参见其文档)。
\documentclass[10pt,a4paper]{book}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[subfigure]{tocloft} % add nested figures
\usepackage{subfigure}
\renewcommand{\cftchapdotsep}{\cftdotsep} % Give chapters dots too
\renewcommand{\cftchapfont}{\normalfont} % Change to normal font
\renewcommand{\cftchappagefont}{} % Change to normal font
% Center the word 'CONTENTS' over table of contents
\renewcommand{\contentsname}{\hspace*{\fill}\normalfont\normalsize CONTENTS \hspace*{\fill}}
%add page flush right at top of TOC
\renewcommand{\cftaftertoctitle}{%
\\[\baselineskip]\mbox{}\hfill{\normalfont Page}}
% OP's attempt to control the spacing using tocloft
%\renewcommand{\cftchapafterpnum}{\vspace{\cftbeforechapskip}}
%\renewcommand{\cftsecafterpnum}{\vspace{\cftbeforechapskip}}
\usepackage{etoc}
\newskip\myskip
\myskip\cftbeforechapskip
\cftbeforechapskip0pt\relax
\etocsetstyle{chapter}
{}
{\etociffirst{}{\addvspace{\myskip}}}
{\etocifnumbered
{\etocsavedchaptertocline{\numberline{\etocnumber}\etocname}{\etocpage}}
{\etocsavedchaptertocline{\etocname}{\etocpage}}%
}
{}
\etocsetstyle{section}
{\addvspace{\myskip}}%
{}
{\etocifnumbered
{\etocsavedsectiontocline{\numberline{\etocnumber}\etocname}{\etocpage}}
{\etocsavedsectiontocline{\etocname}{\etocpage}}%
}
{\addvspace{\myskip}}
\etocsetstyle{subsection}
{\addvspace{\myskip}}
{}
{\etocifnumbered
{\etocsavedsubsectiontocline{\numberline{\etocnumber}\etocname}{\etocpage}}
{\etocsavedsubsectiontocline{\etocname}{\etocpage}}%
}
{\addvspace{\myskip}}
\etocsetstyle{subsubsection}
{\addvspace{\myskip}}
{}
{\etocifnumbered
{\etocsavedsubsubsectiontocline{\numberline{\etocnumber}\etocname}{\etocpage}}
{\etocsavedsubsubsectiontocline{\etocname}{\etocpage}}%
}
{\addvspace{\myskip}}
\begin{document}
\tableofcontents
\chapter{First Chapter}
\section{First Section}
\section{Second Section}
\chapter{Second Chapter}
\section{Third Section}
\section{Fourth Section}
\subsection{First Subsection}
\subsection{Second Subsection}
\subsubsection{First Subsubsection}
\subsubsection{Second subsubsection}
\section{Fifth Section}
\section{Sixth Section}
\chapter{Third Chapter}
\end{document}
重点在于它etoc
旨在检测目录中何时从小节转到节或从节转到章等等。
为了实现最大程度的兼容性,我将所有样式加倍为编号和未编号的情况,以便可以更改 secnumdepth 计数器并且它仍然有效。