如何在不使用 tocloft 的情况下删除 ToC 标题的垂直间距?

如何在不使用 tocloft 的情况下删除 ToC 标题的垂直间距?

我正在尝试控制表格内容标题的垂直间距,但是由于同时加载tocloft和,因此遇到了溢出问题titletoc。我发现了类似的情况,但仅仅删除tocloft是不行的,因为我需要删除标题和条目之间的间距。

自定义目录文本溢出

Overflow!

以下是 MWE:

\documentclass[12pt]{report}

    \usepackage{tabto}

    \usepackage{tocloft}
        \setlength\cftaftertoctitleskip{0pt}

    \usepackage{titletoc}
        \titlecontents{chapter}% <section-type>
            [0pt]% <left>
            {\vspace{1em}}% <above-code>
            {\MakeUppercase \chaptername\ \thecontentslabel \tabto{1.25in} \MakeUppercase}% <numbered-entry-format>
            {}% <numberless-entry-format>
            {\titlerule*[5pt]{.}\contentspage}% <filler-page-format>

        \titlecontents{section}% <section-type>
            [0pt]% <left>
            {\vspace{0.5em}}% <above-code>
            {\tabto{0.5in} \thecontentslabel \tabto{1.25in}}% <numbered-entry-format>
            {}% <numberless-entry-format>
            {\titlerule*[5pt]{.}\contentspage}% <filler-page-format>

        \titlecontents{subsection}% <section-type>
            [0pt]% <left>
            {}% <above-code>
            {\tabto{1.25in} \thecontentslabel \tabto{2.0in}}% <numbered-entry-format>
            {}% <numberless-entry-format>
            {\titlerule*[5pt]{.}\contentspage}% <filler-page-format>

\begin{document}
    \tableofcontents

    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
\end{document}

答案1

除了使用tocloft,您还可以修补\tableofcontents命令以在标题后插入一些负垂直间距,如下所示:

\usepackage{etoolbox}
\patchcmd{\tableofcontents}{\@starttoc}{\vspace{-1cm}\@starttoc}{}{}

这样就将空间减少了1cm。删除tocloft包意味着溢出问题消失了。

Sample output

\documentclass[12pt]{report}

    \usepackage{tabto}

    \usepackage{titletoc}
        \titlecontents{chapter}% <section-type>
            [0pt]% <left>
            {\vspace{1em}}% <above-code>
            {\MakeUppercase \chaptername\ \thecontentslabel \tabto{1.25in} \MakeUppercase}% <numbered-entry-format>
            {}% <numberless-entry-format>
            {\titlerule*[5pt]{.}\contentspage}% <filler-page-format>

        \titlecontents{section}% <section-type>
            [0pt]% <left>
            {\vspace{0.5em}}% <above-code>
            {\tabto{0.5in} \thecontentslabel \tabto{1.25in}}% <numbered-entry-format>
            {}% <numberless-entry-format>
            {\titlerule*[5pt]{.}\contentspage}% <filler-page-format>

        \titlecontents{subsection}% <section-type>
            [0pt]% <left>
            {}% <above-code>
            {\tabto{1.25in} \thecontentslabel \tabto{2.0in}}% <numbered-entry-format>
            {}% <numberless-entry-format>
            {\titlerule*[5pt]{.}\contentspage}% <filler-page-format>

\usepackage{etoolbox}
\patchcmd{\tableofcontents}{\@starttoc}{\vspace{-1cm}\@starttoc}{}{}

\begin{document}


    \tableofcontents

    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
    \chapter{A Chapter}
        \section{A Section}
            \subsection{A Sub-Section}
\end{document}

相关内容