1

I use the tocloft package to customize the format of TOC and the ctex package to support Chinese typesetting and to customize the section title format. Everything works well. But I find that the vertical spacing before the title of TOC is slightly smaller than that before the normal section title. Here is MWE:

%!TeX program = xelatex
\documentclass{article}

% for Chinese typesetting
\usepackage[heading=true]{ctex}
\ctexset{
    section/format = \bfseries \centering \LARGE
}

\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\hfill \bfseries \LARGE}
\renewcommand{\contentsname}{目录}
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cftbeforesecskip}{0em}
\renewcommand{\cftsecdotsep}{\cftdotsep}

\usepackage{fancyhdr}
\fancypagestyle{main}{
    \fancyhf{}
    \fancyhead[C]{Paper}
    \fancyfoot[C]{\thepage}
}

\makeatletter
\renewcommand{\maketitle}{
    \begin{titlepage}
    \vspace*{\fill}
    \begin{center}
    {\Huge\bfseries\@title} \\
    \vspace{2em}
    {\Large\@author} \\
    \vspace{\stretch{3}}
    {\large\@date}
    \end{center}
    \vspace{\stretch{0.5}}
    \end{titlepage}
}
\makeatother

\AtBeginDocument{
    \let \oldtableofcontents \tableofcontents
    \renewcommand{\tableofcontents}{
        \fancypagestyle{plain}{
            \fancyhf{}
            \fancyhead[C]{Paper}
        }
        \pagestyle{plain}
        \oldtableofcontents
        \clearpage
        \pagestyle{main}
    }
}

\title{标题}
\author{作者}
\date{\today}

\begin{document}
\maketitle
\tableofcontents

\section{第一节}
    这是第一节。This is the first section.

\section{第二节}
    这是第二节。This is the second section.
\end{document}

enter image description here enter image description here

It can be seen, though not obvious, that the vertical spacing before TOC title is smaller. I tried to solve this problem and I found this question. Add this code in my preamble:

\renewcommand{\cftbeforetoctitleskip}{10em}

But it has no effect.

Then I read the doc of tocloft package and found the definition of TOC title:

\newcommand{\@cftmaketoctitle}{%
 \addpenalty\@secpenalty
 \if@cfthaschapter
 \vspace*{\cftbeforetoctitleskip}%
 \else
 \vspace{\cftbeforetoctitleskip}%
 \fi
 \@cftpagestyle
 {\interlinepenalty\@M
 {\cfttoctitlefont\contentsname}{\cftaftertoctitle}%
 \cftmarktoc
 \par\nobreak
 \vskip \cftaftertoctitleskip
 \@afterheading}}

So the problem might come from \vspace,I renewcommand this macro by substitute \vspace to \vspace*. But this time, a new problem arose! The spacing became larger: enter image description here

I finally solved this problem by renewcommanding \@cftmaketoctitle like this:

\renewcommand{\@cftmaketoctitle}{%
 \section*{\contentsname}
 \@afterheading}}

enter image description here To make the TOC title become a section title without numbering and its above spacing is controled by ctex package.

But I still can't figure out why those problem happened. Does tocloft conflict with ctex?

  • If the TOC title should be a normal unnumbered section title, set option titles for package tocloft: \usepackage[titles]{tocloft}. – esdd May 16 at 10:18
  • @esdd Oh, thanks:). This works and is simpler. I should read the doc more carefully. – North May 16 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.