TOCStyle – Moving from TOCStyle to TOCBasic in LaTeX

dotfilltocbasictocstyle

I have been using tocstyle until it was removed.
Here is my definition

\usepackage[%
%%% toc width calculation 
  tocindentauto,     % all widths at the TOCs are calculated by tocindentauto
%%% indentation of toc
  tocgraduated,      % standard
%%%  page breaking rules
  tocbreaksstrict,   % sets a lot of penalties before and after TOC entries 
                     % to avoid page break between a TOC entry and it's parent. 
%%%  indentation of unnumbered TOC entries
  toctextentriesleft,   % indented as if they have an empty number.
]{tocstyle}

enter image description here

I have found this definition for tocbasic and changed the second line to \dotfill, but the dotted line is different to before

\DeclareTOCStyleEntries[
raggedentrytext,
linefill=\hfill,
numwidth=0pt,
numsep=1ex,
dynnumwidth
]{tocline}{chapter,section,subsection,subsubsection,paragraph,subparagraph}

\DeclareTOCStyleEntries[
linefill=\dotfill,
indent=0pt,
dynindent
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph}

\setkomafont{chapterentry}{\bfseries}

So the question is how to restore the dotted line with spacing as in the first example?

enter image description here

Best Answer

Package tocbasic provides \TOCLineLeaderFill for the dotted line between the entry text and the page number in TOC. So you could use

hfill=\TOCLineLeaderFill

But chapter entries without dots and other levels with dots are the default for book and report classes! Therefore you simple have to remove all your hfill settings to get the desired result.

Example:

\documentclass{scrbook}

\DeclareTOCStyleEntries[
  %raggedentrytext,
  numwidth=0pt,
  numsep=1ex,
  dynnumwidth
]{tocline}{chapter,figure,table}

\DeclareTOCStyleEntries[
  %raggedentrytext,
  numwidth=0pt,
  numsep=1ex,
  dynnumwidth,
  indent=0pt,
  dynindent,
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph}

\setkomafont{chapterentry}{\bfseries}

\setcounter{tocdepth}{\subsubsectiontocdepth}

\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Introduction}
\chapter{Theory}
\section{Section heading}
\subsection{Subsection heading}
\subsubsection{Subsubsection heading}
\end{document}

enter image description here

If you do not use a KOMA-Script class, you have to load package tocbasic and have to declare that the section indent follows the chapter settings and the paragraph indent follows the indent and number width of subsubsection entries.

\documentclass{book}

\usepackage{tocbasic}
\DeclareTOCStyleEntries[
  indentfollows={chapter,subsubsection}
]{tocline}{section,paragraph}

\DeclareTOCStyleEntries[
  %raggedentrytext,
  numwidth=0pt,
  numsep=1ex,
  dynnumwidth
]{tocline}{chapter,figure,table}

\DeclareTOCStyleEntries[
  %raggedentrytext,
  numwidth=0pt,
  numsep=1ex,
  dynnumwidth,
  indent=0pt,
  dynindent,
]{tocline}{section,subsection,subsubsection,paragraph,subparagraph}

\setcounter{tocdepth}{\subsubsectiontocdepth}

\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Introduction}
\chapter{Theory}
\section{Section heading}
\subsection{Subsection heading}
\subsubsection{Subsubsection heading}
\end{document}

enter image description here