# How to get dotted leads in ToC using book class

I am using the book class and I need dotted leads in the ToC for chapters. tocloft package doesn't seem to work. I am using TexShop.

I currently have this:

\documentclass[12pt, oneside]{book}

\begin{document}

\tableofcontents

\begin{mainmatter}

\chapter{Chapter 1}

\section{section 1}
\subsection{subsection}
\section{section 2}

\chapter{Chapter 2}

\end{mainmatter}
\end{document}


The sections have dotted leads but the chapters do not.

I have tried including the tocloft package but couldn't get it to work:

\documentclass[12pt, oneside]{book}

\usepackage{tocloft}

\begin{document}

\tableofcontents

\begin{mainmatter}

\chapter{Chapter 1}

\section{section 1}
\subsection{subsection}
\section{section 2}

\chapter{Chapter 2}

\end{mainmatter}
\end{document}


I get an error saying 'Undefined Control Sequence'

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded                         format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./testingTOC.tex
LaTeX2e <2015/01/01>
Babel <3.9l> and hyphenation patterns for 21 languages loaded.
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/book.cls
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2015basic/texmf-dist/tex/latex/base/bk12.clo))
(./tocloft.sty (./stdclsdv.sty)) (./testingTOC.aux) (./testingTOC.toc
./testingTOC.toc:1: Undefined control sequence.
{\cftdotsep }
l.1 ...line {chapter}{\numberline {1}Chapter 1}{1}

? ]

• Welcome to TeX.SX! Could you please provide a minimal working example that shows your problem in as little code as possible? – riddleculous Apr 10 '16 at 0:18
• please add it to your question completely (you accidentally sent the comment, I guess) and use the {} button to make it a code block – riddleculous Apr 10 '16 at 0:37
• for me your MWE works (and produces the desired output), if I insert the tocloft package and the renewcommand. – riddleculous Apr 10 '16 at 0:48
• I copied and pasted your edited version - still working perfectly. Could you post the whole error message? – riddleculous Apr 10 '16 at 0:49

This is what I ended up getting to work:

\documentclass[12pt, oneside]{book}
\usepackage{tocloft}
\renewcommand\cftchapdotsep{\cftdotsep}

\begin{document}

\tableofcontents

\begin{mainmatter}

\chapter{Chapter 1}

\section{section 1}
\subsection{subsection}
\section{section 2}

\chapter{Chapter 2}

\end{mainmatter}
\end{document}


Here is a solution without tocloft, by redefinition of \l@chapter, adding the \@dottedtocline command inside and adjusting the horizontal skips.

\documentclass[12pt, oneside]{book}

\usepackage{showframe}
\makeatletter

\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\begingroup
\parindent\z@
\rightskip\@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode
\@dottedtocline{0}{0em}{1.5em}{%
\bfseries #1}{\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}}%
\penalty\@highpenalty
\endgroup
\fi
}
\makeatother

\begin{document}

\tableofcontents

\begin{mainmatter}

\chapter{Chapter 1}

\section{section 1}
\subsection{subsection}
\section{section 2}

\chapter{Chapter 2}

\chapter{Chapter with a very long title that is completely useless but we will try it }
\section{section 1}
\subsection{subsection}

\end{mainmatter}
\end{document}