I'm using a third-party non-standard document class which is based on book
. Class be damned, I want to add dot leaders for chapters, sections and subsections in the Table of Contents. If I include tocloft
, it changes the layout of the Table of Contents in undesirable ways. It also seems that the tocstyle
package is for switching high-level styles, etc.
So I would like to add dot leaders without radically changing the layout of the ToC. Does anyone know how this might be acheived?
I also looked into the titletoc
package which doesn't change the original ToC layout. However, the only way I could find to add a leader would be to use the following:
\titlecontents{<section>}[<left>]{<above>}{<before with label>}{<before without label>}{<filler and page>}[<after>]
I could just insert leader
into the filler option, but I would have to redefine the entire style of the ToC to achieve this.
I'm embarrassed to say I've been at this about an hour (LaTeX humbles you sometimes I guess). All answers I've found through Google just say to use tocloft
. Wondering if anyone has a better idea?
Best Answer
book
defines the ToC-related sectioning commands as follows:The above boils down to adding a dotted ToC line for
\section
,\subsection
,\subsubsection
,\paragraph
and\subparagraph
(if allowed in the ToC; set viatocdepth
). It doesn't for\chapter
though. However, the definition of\@dottedtocline
can be worked into\l@chapter
. Here's the definition, taken fromlatex.ltx
:which leads to the following choice for
\l@chapter
:Here's a complete MWE:
I've used
\xleaders
instead of\leaders
, but this may be a personal preference. See a discussion on the difference at Want to fill line with repeating string.