This question is a hopefully a clearer statement of a previous question.
I am using titletoc
to format my Table of Contents.
Two notes right from the start:
1: in my actual document, I am also using titlesec
. Thus, I should not switch to toctofl
, as using toctofl
and titlesec
together is not recommended.
2: Another suggestion might be to switch to the memoir
class, which has extensive support for customizing the formatting of the section titles and the ToC. However, switching to the memoir
class is not practical, since my actual document has tons of other formatting and customizations that I would have to revisit if I were to make that switch. (Moreover, for all I know, the same problem as the one I'm about to describe might happen in the memoir
class as well.)
The ToC format I'm trying to achieve is the following:
The important features are:
The names of the sections have a right margin that is much larger than (i.e. it is far to the left from) the right margin of the dots.
The dots, however, don't start at the right margin of the names of the sections. Rather, they start wherever each individual section title ends, which will generally be to the left of the right margin of the titles. The dots end at their own right margin, which is much smaller (i.e. it is much further to the right, almost all the way to the page numbers).
The code used to generate the above was the following:
\documentclass[12pt]{report}
\usepackage[paper=letterpaper,left=1.25in,right=1in]{geometry}
\usepackage{titletoc}
\contentsmargin[160bp]{15pt} % if we change 160bp to 175bp, we get a problem.
\dottedcontents{section}[1in]{}{2em}{3.3pt}
\begin{document}
\tableofcontents
\section{As any dedicated reader can clearly see, the Ideal of practical reason is a representation of, as far as I know, the things in themselves; as I have shown elsewhere, the phenomena should only be used as a canon for our understanding.}
% \section{It must be supposed that ours faculties haberdashery}
\section{The paralogisms of practical reason are what first give rise to the architectonic of practical reason.}
\section{As is proven in the ontological manuals, it is obvious that the transcendental unity of apperception proves the validity of the Antinomies; what we have alone been able to show is that, our understanding depends on the Categories.}
\end{document}
All too often, however, I run into the following problem: one or more of the ToC entries end up looking like the first ToC entry here:
As you can see, in the first entry, the dotted line has disappeared and the page number is displayed far to the left.
This second, problematic output was generated using the same code as the first output, except that the value of the optional argument of \contentsmargin
was slightly different, as indicated in the comment in the code.
The way it usually happens is this: we pick some reasonable values for the various parameters of titletoc
. We generate our document. We notice that some entries in the ToC suffer the problem I just described. We tweak the values of one or more of the titletoc
parameters until he problem—hopefully!—disappears.
Tweaking the optional argument of \contentsmargin
is not the only way to correct the problem. We could instead tweak one of the other parameters, or slightly rewrite the problematic title (often it suffices to add an extra space at the end).
But all this is very annoying, especially in documents with many chapters, sections, and subsections. First of all, it is completely unpredictable when the problem will arise, and so one must keep constantly (and very carefully) checking the ToC output. Secondly, it will often happen that a parameter tweak that cures the problem in one entry causes the same kind of problem to appear in another entry.
Question
How can I reliably generate ToCs with the formatting I described, without the above problem arising, and so without any need to constantly be on the lookout for possibly needing to tweak either the length parameters of titletoc
or the section titles themselves? The solution should work, automatically, no matter (within reason) what the right margin of the titles is, no matter (within reason) what the right margin of the dots is, and no matter (within reason) what the section titles may be.