0

I would simply like to center the title of the table of contents in my "book" document.

I just added dot leaders to the table of contents, and this appeared to be best accomplished by forgoing the tocloft package and instead using the \dottedcontents command of the titlesec companion package, titletoc, like so:

\dottedcontents{chapter}[0em]{\vspace{2.1ex}}{0em}{0.5pc}

Introducing tocloft settings in order to center the TOC title causes what appears to be a vertical placement/spacing problem that I'm not sure how to correct (this is described in detail in my comments to Peter's answer below). I would therefore like to avoid using the tocloft package if possible.

One way to approach the centering task would be to add \centering to the chapter \titleformat command of the titlesec package:

\usepackage{titlesec}
\titleformat{\chapter}[display]{\centering\Large\bfseries}{}{}{}

However this centers all chapter titles, and I don't want this.

So, my question is: what is the simplest way to center the table of contents title without affecting other chapter titles and without using tocloft?

Here is a near minimal example (with my attempts at using the tocloft package omitted):

\documentclass{book}

\usepackage{titlesec}
\titleformat{\chapter}[display]{\Large\bfseries}{}{}{}

\usepackage{indentfirst}

\usepackage{titletoc}
\dottedcontents{chapter}[0em]{\vspace{2.1ex}}{0em}{0.5pc}

\begin{document}

\tableofcontents
\vspace{24pt}

\chapter*{Left-Justified Chapter 1}
\addcontentsline{toc}{chapter}{Left-Justified Chapter 1}

Some indented text.

\chapter*{Left-Justified Chapter 2}
\addcontentsline{toc}{chapter}{Left-Justified Chapter 2}

More indented text.

\end{document}
  • 2
    Why do you use \section* for what's supposed to be a chapter? – Bernard Mar 10 at 11:18
  • Just to allow "chapters" 1 and 2 to appear on the same page as the table of contents while working with the minimal example on my system. These can be changed to \chapter* for consistency, and I've done so above to avoid confusion. – SapereAude Mar 10 at 11:55
  • By default the tocloft package does not change the ToC (or LoF or LoT) layout from that of the standard classes, except that they need not start on new pages. I don't know what you might have done to change these to results you don't like. – Peter Wilson Mar 10 at 19:16
  • Hi Peter, see my comments under your answer below. – SapereAude Mar 11 at 1:15
1

You can declare a \titleformat within a group, after \begin{document}.

Unrelated: with the companion package titletoc, you have a much simpler way to format the entries in the table of contents, with the \dottedcontents command.

\documentclass{book}

\usepackage{titlesec, titletoc, xcolor}
\titleformat{\chapter}[display]{\Large\bfseries}{}{}{}

\usepackage{indentfirst}

\dottedcontents{chapter}[3.8em]{\vspace{2ex}}{2.3em}{0.8pc}

\begin{document}

\begingroup
\titleformat{\chapter}[block]{\Large\bfseries\filcenter}{\color{red}}{}{}
\tableofcontents
\vspace{24pt}
\endgroup

\chapter*{Left-Justified Chapter 1}
\addcontentsline{toc}{chapter}{Left-Justified Chapter 1}

Some indented text.

\chapter*{Left-Justified Chapter 2}
\addcontentsline{toc}{chapter}{Left-Justified Chapter 2}

More indented text.

\end{document} 

enter image description here

0

By default the tocloft package uses the standard class's (book, report, article) settings for the ToC, LoF and LoT. The following (less any typos) is a solution to your problem using tocloft.

\documentclass{book}
\usepackage{tocloft}

%% center Contents title
\renewcommand{\cfttoctitlefont}{\hfill\Huge\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}

%% add dot leaders to chapters
\renewcommand{\cftchapdotsep}{\cftdotsep}

\begin{document}
\tableofcontents
\chapter{First chapter}
\section{A section}
\subsection{A subsection}
\end{document}

This makes no changes to the indentation and vertical placement of the entries.

  • Hi Peter, thanks for the MWE. For the code you wrote, I find that including the tocloft package and related settings (as opposed to commenting them out) not only centers the title and adds dot leaders, but also raises both the title and entries by about the height of the title. This upward shift is one example of what I'm calling an unwanted change in vertical placement. – SapereAude Mar 11 at 1:10
  • Additionally, when the TOC is long enough, LaTeX apparently may adjust vertical spacing between entries so that the final entry on the page is a fixed distance from the bottom of the page. This means that the upward shift that I just described can lead to differences in inter-entry spacing. Hope this clarifies what I meant. Thanks for encouraging me to look at this more closely. – SapereAude Mar 11 at 1:12
  • Finally, it turned out that the indentation issue that I mentioned in my original question had another explanation (tocloft was not to blame), and I have edited my question accordingly. Thanks, Peter. – SapereAude Mar 11 at 2:34
  • @SapereAude When I processed my MWE there was no change in the vertical position of the title or entries. For long (multipage) ToCs LaTeX will alter, or not, the vertical spacing between the entries according as to whether \raggedbottom or \flushbottom is in effect. – Peter Wilson Mar 12 at 19:05
  • Interesting. The upward vertical shift, which on closer inspection appears to be the line width of a TOC entry, is quite reproducible on my end. In such a minimal example, it was not easy for me to see this difference without printing out the TOC with and without the tocloft lines commented out. In any event, I've opened a new question about this. – SapereAude Mar 13 at 4:36

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.