See MWE below.
How can I remove the indent in front of the section entries in the partial ToC
(only there, not in the normal ToC)?
\documentclass{book}
\usepackage{titletoc}
\usepackage{lipsum}
\begin{document}
\setcounter{tocdepth}{2}
\tableofcontents
\chapter{A chapter}
\startcontents[chapters]
\printcontents[chapters]{}{1}{}
\section{Section}
\subsection{Subsection}
\lipsum[4]
\subsection{Another Subsection}
\lipsum[1]
\section{Section 2}
\lipsum
\chapter{Second chapter}
\startcontents[chapters]
\printcontents[chapters]{}{1}{}
\section{Section}
\lipsum[2]
\section{Another section}
\lipsum
\end{document}
This question is related to this answer.
Best Answer
In order to do this, you need to create a separate format for the partial TOCs by using
titletoc
's prefix system.Creating separate formatting for the partial TOCs
First we create the format for a
psection
instead of asection
using the regular\titlecontents
command. This can be formatted however you like. To make it flush with the left margin we make the left margin2.3em
(same width as the space set up for the section number). Then when we use the\printcontents
command to produce the partial contents we use the{p}
prefix argument to telltitletoc
to use the format defined forpsection
instead ofsection
. You need to determine the formatting for the subsections in the same way if you have subsections. I've removed some extra space that I added before.Here's an example:
Choosing the correct spacing values
The values you choose to format the margins for the various levels can be set by hand. The default values used by the
book
class are the following. These values are those passed to the\@dottedtocline
command within the internal sectioning command definitions. They were obtained from the source code ofbook.cls
.You can use these values to determine the values for the
\titlecontents
parameters for the various sections. Since our partial TOCs don't have a chapter level, we start the left margin at the width of the label for section (2.3em) and then use the same value for the label width. To make the subsections indent exactly the same amount as in the main TOC relative to the section, we make the left margin = previous left margin + current label width, i.e. 5.5em. Lower levels proceed similarly.