0

I am using the book document class, and have parts, chapters, and sections.

I set the tableofcontents to show just parts and chapters:

\setcounter{tocdepth}{0}

However, now the TOC has large spacing between all the items, and everything is bold.

Ideally, I would like the formatting to be similar to the default behaviour when there are chapters and sections.

The default behavior is:

Chapters bold and spaced; sections normal and close together.

I'd like:

Parts bold and spaced; chapters normal and close together.

1
  • 1
    You're request deliberately depends on the document class and perhaps which packages are used -- you provided no information on this
    – user31729
    Commented Aug 29, 2017 at 13:12

1 Answer 1

5
\documentclass[]{book}

\setcounter{tocdepth}{0}

\makeatletter
\let\l@part\l@chapter
\def\l@chapter{\@dottedtocline {0}{1.5em}{2.3em}}
\makeatother

\begin{document}
\tableofcontents
\part{I should create MWEs}
\chapter{In the future I'll provide a MWE}
\chapter{I promise to provide MWEs when I ask on TeX.SX}
\part{I really should create MWEs}
\chapter{In the future I'll provide a MWE}
\chapter{I promise to provide MWEs when I ask on TeX.SX}
\part{I will accept answers}
\chapter{I will upvote answers}
\end{document}

Explanation: The macros responsible for typesetting the ToC are all of the form layer name prefixed with \l@. To put it simple \let changes the definition of the first macro-name to the second's. And \@dottedtocline is the macro responsible for typesetting those dotted ToC lines. The first argument is the tocdepth (chapter is 0) the other two are indents.

6
  • You forgot: \part{I will accept answers} and \chapter{I will upvote answers} ;-)
    – user31729
    Commented Aug 29, 2017 at 13:17
  • @ChristianHupfer edit is on the way, thanks for reminding!
    – Skillmon
    Commented Aug 29, 2017 at 13:17
  • That worked perfectly. You've basically trained me not to use MWE. JK! Lesson learned...
    – Dr Xorile
    Commented Aug 29, 2017 at 13:22
  • 1
    @DrXorile that's because I'm more the forgiving type. And I hoped to brainwash you with the chapter and part names despite not waiting for a MWE. And the above might have failed badly if you used any package altering the toc.
    – Skillmon
    Commented Aug 29, 2017 at 13:23
  • 1
    @DrXorile small explanation added.
    – Skillmon
    Commented Aug 29, 2017 at 13:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .