[Tex/LaTex] Table of contents in scrbook/komascript: add dots to chapter titles

koma-scriptscrbooktable of contentstocstyle

I need to customize the appearance of my table of contents according to the requirements of a publisher.

Here is a minimal example of what it looks like right now:

\documentclass{scrbook}

\begin{document}

\frontmatter

\tableofcontents

\chapter{Preface}

\mainmatter

\part{First part}

\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\subsection{Second subsection}
\section{Second section}

\chapter{Second chapter}

\end{document}

This produces something that looks like this:


Screenshot of my current TOC


Now my publisher requested that the chapter titles should have dots between title and page number.

I have found the tocstyle package, but I don't understand its documentation. I am not even sure the package lets me do what I need to do. Can somebody please make suggestions on how to get what I want? Thanks.

Edit: I need to remove the part page numbers as well. I posted this requirement in my original question, but multiple questions per thread were discouraged. However, later it turned out that this can actually make a difference also for the question asked here: If I use tocstyle to suppress page part numbers, this may affect the solutions posted here to get rid of the chapter dots.

Best Answer

Do not use package tocloft (mentioned in your own answer) together with a KOMA-Script class.

There is an KOMA-Script option to fill the space between the chapter title and the pagenumber in TOC with dots:

\KOMAoptions{toc=chapterentrydotfill}

enter image description here


If the page numbers for the chapter headings should not be bold use

\addtokomafont{chapterentrypagenumber}{\mdseries}

It is also possible to remove the page number for the part headings from TOC:

\addtokomafont{partentrypagenumber}{\nullfont}

enter image description here

Code:

\documentclass[toc=chapterentrydotfill]{scrbook}
\addtokomafont{chapterentrypagenumber}{\mdseries}
\addtokomafont{partentrypagenumber}{\nullfont}
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\mainmatter
\part{First part}
\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\subsection{Second subsection}
\section{Second section}
\chapter{Second chapter}
\end{document}

It is also possible to use package tocstyle which is part of the KOMA-Script bundle. To get dots between the headings off all levels and the page numbers in TOC use

\usetocstyle{allwithdot}

as already suggested by @Peter Ebelsberger. To remove the dots and the page numbers for the part headings in TOC add

\settocstylefeature[-1]{leaders}{\hfill}
\settocstylefeature[-1]{pagenumberhook}{\nullfont}

MWE:

\documentclass{scrbook}
\usepackage{tocstyle}
\usetocstyle{allwithdot}
\settocstylefeature[-1]{leaders}{\hfill}
\settocstylefeature[-1]{pagenumberhook}{\nullfont}
\begin{document}
\frontmatter
\tableofcontents
\chapter{Preface}
\mainmatter
\part{First part}
\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\subsection{Second subsection}
\section{Second section}
\chapter{Second chapter}
\end{document}

Run several times to get

enter image description here

Related Question