# Reproducing the standard layout of the “book” class with “titletoc”

Is there a reference that shows how to use titletoc commands (\titlecontents, etc.) to approximate the layout of the table of contents in the standard book class?

In particular, I would like to see how to do this for the full range of sectioning commands, including \part and \chapter.

• Can you elaborate on what you are trying to achieve, what you need this for, what you want to do? So far, the question hasn't seen much attention. – Johannes_B Feb 13 '15 at 9:50
• @Johannes_B: Often it happens that in general I like the layout of the standard table of contents, but I would just like to modify some particular detail (e.g., some details of the spacing, fonts, etc.). How do you do that with titletoc? If there was an example of how to reproduce the standard table of contents, then I could first just copy-paste that to my document, and then tweak it a bit. – Jukka Suomela Feb 13 '15 at 11:14
• Section 9.2 of the titlesec manual shows how to redefine the standard section commands. This is very helpful, I can just copy-paste it and then start tweaking it. With titletoc I haven't found anything similar. And with titletoc it is even worse, as the interface is much more complicated and there are more parameters to guess. – Jukka Suomela Feb 13 '15 at 11:16
• Ah, ok, now i understand it. Gimme a bit of time, never used titletoc before. Dunno, if i can find something reliable, either. But my question will also mention package tocstyle. ;-) – Johannes_B Feb 13 '15 at 15:04

I couldn't find any reference on how one would define the layout of the standard classes using titletoc.

One place to look it up would be the class file itself, for a chapter in the report and book class, we get the following definition.

\newcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\hskip -\leftskip
#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
\penalty\@highpenalty
\endgroup
\fi}


After a bit of playing around, i still couldn't get any satisfying result.

\documentclass{book}
\usepackage{titletoc}
\titlecontents{chapter}[0pt]{\vspace{1em}\bfseries}{\thecontentslabel\enspace}{}{\hfill\contentspage}[\vspace{2pt}]
\usepackage{blindtext}
\usepackage{showframe}
\begin{document}
\tableofcontents
\blinddocument
\backmatter
\blinddocument
\end{document}


A package still in alpha but nevertheless very useful is package tocstyle that does the hook approach titletoc wants to prevent. This makes it relatively easy to change the appearance for small parts only.

For example, if you want for very odd reason to have just the pagenumbers larger and without serifs, you can do the following.

\documentclass{book}
\usepackage{blindtext}
\usepackage{showframe}
\usepackage{tocstyle}
\usetocstyle{standard}
\settocfeature{pagenumberhook}{\Large\sffamily}
\begin{document}
\tableofcontents
\blinddocument
\backmatter
\blinddocument
\end{document}


Good to demonstrate a point, but not for having in an own document.

For the chapter style in the ToC, the following code seems to reproduce the book class style slightly more accurately than the code by Johannes_B:

\documentclass{book}
\usepackage{titletoc}
\usepackage{blindtext}
\usepackage{showframe}

\titlecontents{chapter}
[1.5em]
{\contentslabel{1.3em}}
{\hspace*{-1.3em}}
{\titlerule*[.5pc]{}\contentspage}

% code by Johannes_B:
%\titlecontents{chapter}
%    [0pt]
%    {\vspace{1em}\bfseries}
%    {\thecontentslabel\enspace}
%    {}
%    {\hfill\contentspage}[\vspace{2pt}]

\begin{document}
\tableofcontents
\blinddocument
\backmatter
\blinddocument
\end{document}