Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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 a section using the regular \titlecontents command. This can be formatted however you like. To make it flush with the left margin we make the left margin 2.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 tell titletoc to use the format defined for psection instead of section. 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:

\documentclass[oneside]{book}
\usepackage{titletoc}
\usepackage{lipsum}

\setcounter{tocdepth}{2}  
\begin{document}
\titlecontents{psection}[2.3em]
{} {\contentslabel{2.3em}} {} {\titlerule*[1pc]{.}\contentspage}
\titlecontents{psubsection}[5.5em]
{} {\contentslabel{3.2em}} {} {\titlerule*[1pc]{.}\contentspage}

\tableofcontents
\chapter{A chapter}
\startcontents[chapters]
\printcontents[chapters]{p}{1}{}
\section{Section}
\lipsum[1]
\subsection{A subsection}
\lipsum[3]
\subsection{A second subsection}
\lipsum[4]
\section{Section 2}
\lipsum
\chapter{Second chapter}
\startcontents[chapters]
\printcontents[chapters]{p}{1}{}
\section{Section}
\lipsum[2]
\section{Another section}
\lipsum
\end{document}

partial output of code

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 of book.cls.

   Level       Indent  Label width

section         1.5em     2.3em
subsection      3.8em     3.2em
subsubsection   7.0em     4.1em
paragraph      10.0em     5.0em  
subparagraph   12.0em     6.0em

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.

share|improve this answer
    
I have two criticisms: 1) The blank between section number and section title is much bigger than in the normal ToC. 2) The horizontal alignement of subsections in the partial ToC is not quite right. [See my edited question where I have added subsections.] –  lpdbw Aug 8 '12 at 17:00
1  
@lpdbw That space is the \quad I inserted. I've removed it. For subsections you need to add a separate \titlecontents for that too, otherwise it defaults to whatever is set for the main TOC. I've added that to the revised answer. –  Alan Munn Aug 8 '12 at 17:31
    
Thanks! Can you tell me how, in general, I can see what I have to substitute for [2.3em] and \contentslabel{2.3em} in order to get the correct alignment for level <x>? One might also have subsubsections and paragraphs and tocdepth{4}. It would be therefore useful to know what the effect of [2.3em] and \contentslabel{2.3em} is and where one can look up the right settings for all ToC levels ... –  lpdbw Aug 8 '12 at 18:29
    
@lpdbw Most of this is described in §6.1 of the titlesec documentation. The left margin is where the entry wraps to, and doesn't include the space taken up by the label, so to get the label lined up you need to increase the left margin by the space taken up by the label. This value is additive, so for every subsequent level, you need to add the space taken up by the previous level as well. I don't know if there's a simple way to calculate this automatically. –  Alan Munn Aug 8 '12 at 18:42
1  
@lpdbw I've added some more explanation of the spacing calculation, and updated the answer to use the same values as book uses in the main TOC. –  Alan Munn Aug 8 '12 at 19:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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