删除目录标题前的垂直空格

删除目录标题前的垂直空格

我一直在尝试找出一种方法来轻松减少从页面顶部到目录标题的空间/间隙,就像减少目录开始前的垂直空间一样。

以下是我的 MWE:

\documentclass[final,a4paper,11pt]{report}

%%% Packages %%%
\usepackage[hidelinks,breaklinks]{hyperref} % hyperref for linking references for pdf
\usepackage{tocloft}    % tocloft for table of contents style
\usepackage[compact]{titlesec}  % titlesec for title section layout

% Format the title for chapters
\titleformat{\chapter}[hang]{\huge\bfseries}{\thechapter.}{1em}{}
\titlespacing*{\chapter}{0pt}{-3em}{1.1\parskip}
\titlelabel{\thetitle\quad}

% Begin document
\begin{document}

\tableofcontents
\addtocontents{toc}{\vskip-40pt} % this is to reduce the gap for the first table of contents entry

\clearpage

\chapter{Introduction}
\section{Background}
Need to reduce the space before the Contents title, was able to reduce the space before chapter fine.
\end{document}

类如何report处理目录?它似乎不是一个章节,否则当我更改章节间距时它会向上移动吗?

答案1

我通过使用以下包解决了这个问题\usepackage{tocloft}

\setlength{\cftbeforetoctitleskip}{-3em}

之前没有用过,因为我忘了把 Z 改为 toc \cftbeforeZtitleskip:\cftbeforetoctitleskip

我相信 Z 可以改为除了“toc”之外的其他东西

答案2

如果您加载包tocloft,TOC 标题的格式会发生变化。LOF 和 LOT 也会发生同样的情况。要避免此行为,请设置包选项titles

\usepackage[titles]{tocloft}% <- option titles added!

然后,TOC、LOF 和 LOT 标题将是未编号的章节标题,其布局与文档中相同。

例子:

\documentclass[a4paper,11pt]{report}
\usepackage[titles]{tocloft}% <- option titles added!
\usepackage[compact]{titlesec}
\usepackage[hidelinks,breaklinks]{hyperref}

% Format the title for chapters
\titleformat{\chapter}[hang]{\huge\bfseries}{\thechapter.}{1em}{}
\titlespacing*{\chapter}{0pt}{-3em}{1.1\parskip}
\titlelabel{\thetitle\quad}

\begin{document}
\tableofcontents
\chapter{Introduction}
\section{Background}
Need to reduce the space before the Contents title, was able to reduce the space before chapter fine.
\end{document}

结果:

使用 \usepackage[titles]{tocloft}

相关内容