8

I want to customize my table of contents and lists of figures and tables using tocbasic. I originally did these customizations with tocloft. I managed to get almost everything done. However there are 2 issues remaining:

  1. Creating standalone styles instead of using the options to tocline
  2. It seems the dynnumwidth and numsep options don't have any effect

I'd like to create a standalone style for each of chapter, section, subsection, subsubsection, figure, and table. I know there is \CloneTOCEntryStyle{tocline}{chapter} but I don't think it is possible to clone it with the options set.

Below is a complete MWE.

\documentclass[fontsize=11pt]{scrreprt}

\usepackage[left=25mm,right=25mm,top=8.4mm,bottom=10.7mm%
    ,includeheadfoot,headsep=15.4mm,marginparwidth=18mm,marginparsep=4mm]%
    {geometry}

\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

\usepackage{blindtext}

\makeatletter
\newcommand*{\skillmon@chapter@dotfill}{%
    \def\@dotsep{0.072}\TOCLineLeaderFill[\textbf{.}]%
}
\newcommand*{\skillmon@section@dotfill}{%
    \def\@dotsep{0.072}\TOCLineLeaderFill%
}
\DeclareTOCStyleEntry[%
    ,beforeskip=1.15em plus 1pt%
    ,dynnumwidth=true% commenting out this doesn't change anything
    ,numsep=5pt% changing this to e.g. -5pt doesn't change anything
    ,linefill=\skillmon@chapter@dotfill%
    ,entryformat=\textbf%
    ,indent=0pt%
    ,level=0%
    ,pagenumberbox=\relax%
]{tocline}{chapter}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.3em%
    ,pagenumberbox=\relax%
]{tocline}{section}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=3.38em%
    ,pagenumberbox=\relax%
]{tocline}{subsection}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=6.38em%
    ,pagenumberbox=\relax%
]{tocline}{subsubsection}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.5em%
    ,pagenumberbox=\relax%
]{tocline}{table}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numsep=5pt%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.5em%
    ,pagenumberbox=\relax%
]{tocline}{figure}
\makeatother

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\blinddocument
\addxcontentsline{lot}{table}[1.1]{example of table}
\addxcontentsline{lot}{table}[1.2]{example of table}
\addxcontentsline{lof}{figure}[1.1]{example of figure}
\addxcontentsline{lof}{figure}[1.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[2.1]{example of table}
\addxcontentsline{lot}{table}[2.2]{example of table}
\addxcontentsline{lof}{figure}[2.1]{example of figure}
\addxcontentsline{lof}{figure}[2.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[3.1]{example of table}
\addxcontentsline{lot}{table}[3.2]{example of table}
\addxcontentsline{lof}{figure}[3.1]{example of figure}
\addxcontentsline{lof}{figure}[3.2]{example of figure}
\end{document}
2
  • What's tocbasic? KOMA?
    – cfr
    Jun 10, 2017 at 3:11
  • 1
    @cfr tocbasic is the package KOMA-script uses to format all its lists. It is loaded automatically if you use a KOMA-class (see also the description of the tocbasic-tag).
    – Skillmon
    Jun 10, 2017 at 6:56

1 Answer 1

5

With dynnumwidth=true the value of numwidth is not completly ignored (unlike the documentation). Instead it works as minimum width of the entry numbers including numsep. That means the used width for the entry numbers is at least numwidth, but it will be adjusted if there are numbers which need space wider than numwidth. So the effect of dynumwidth=true and/or changes of numsep is only visible, if the needed space is wider than numwidth. I think the documentation for tocdynnumwidth have to be changed (or it is a bug of tocbasic).

If you add numwidth=0pt to the settings for each TOC style entry, then dynnumwidth and numsep have an effect even if there are only short entry numbers.

\documentclass[fontsize=11pt]{scrreprt}
%\documentclass[11pt]{report}
%\usepackage{tocbasic}% with a KOMA-Script class do not load explicitly

\usepackage[left=25mm,right=25mm,top=8.4mm,bottom=10.7mm%
    ,includeheadfoot,headsep=15.4mm,marginparwidth=18mm,marginparsep=4mm]%
    {geometry}
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}
\usepackage{blindtext}

\makeatletter
\def\@dotsep{0.072}
\newcommand*{\skillmon@chapter@dotfill}{%
    \TOCLineLeaderFill[\textbf{.}]%
}
\newcommand*{\skillmon@section@dotfill}{%
    \TOCLineLeaderFill%
}
\newcommand*\skillmon@pagenumberbox[1]{\makebox{#1}}
\newcommand*\skillmon@numsep{0pt}% <- adjust this to set the minimum space between the numbers and the titles

\DeclareTOCStyleEntry[%
    ,beforeskip=1.15em plus 1pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@chapter@dotfill%
    ,entryformat=\textbf%
    ,indent=0pt%
    ,level=0%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{chapter}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.3em%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{section}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=3.38em%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{subsection}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=6.38em%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{subsubsection}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.5em%
    ,pagenumberbox=\relax%
]{tocline}{table}
\DeclareTOCStyleEntry[%
    ,beforeskip=0pt plus .2pt%
    ,dynnumwidth=true%
    ,numwidth=0pt,% <- added
    ,numsep=\skillmon@numsep%
    ,linefill=\skillmon@section@dotfill%
    ,indent=1.5em%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{figure}
\makeatother

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\blinddocument
\addxcontentsline{lot}{table}[1.1]{example of table}
\addxcontentsline{lot}{table}[1.2]{example of table}
\addxcontentsline{lof}{figure}[1.1]{example of figure}
\addxcontentsline{lof}{figure}[1.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[2.1]{example of table}
\addxcontentsline{lot}{table}[2.2]{example of table}
\addxcontentsline{lof}{figure}[2.1]{example of figure}
\addxcontentsline{lof}{figure}[2.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[3.1]{example of table}
\addxcontentsline{lot}{table}[3.2]{example of table}
\addxcontentsline{lof}{figure}[3.1]{example of figure}
\addxcontentsline{lof}{figure}[3.2]{example of figure}
\end{document}

Now the value of \skillmon@numsep sets the minimum space between the numbers and the titles in ToC. In the example it is set to 0pt.

Run three times to get

enter image description here

Note that this example will also work if you replace scrreprt by the standard class report. But then you have to load package scrtocbasic explicitly.


You are using the KOMA-Script class scrreprt. So it is possible to set the options for the toc entries also in the optional argument of \RedeclareSectionCommand, \RedeclareSectionCommands etc. But note there you have to add the prefix toc to each of these options.

Example:

\documentclass[fontsize=11pt,
%listof=nochaptergap% remove the chapter gap in lists like LOT or LOF
]{scrreprt}[2017/01/03]

\usepackage[left=25mm,right=25mm,top=8.4mm,bottom=10.7mm%
    ,includeheadfoot,headsep=15.4mm,marginparwidth=18mm,marginparsep=4mm]%
    {geometry}

\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

\usepackage{blindtext}

\makeatletter
\def\@dotsep{0.072}
\newcommand*\skillmon@pagenumberbox[1]{\makebox{#1}}
\newcommand*\skillmon@numsep{0pt}

\RedeclareSectionCommands[%
    ,tocnumwidth=0pt%
    ,tocdynnumwidth=true%
    ,tocnumsep=\skillmon@numsep%
    ,tocpagenumberbox=\skillmon@pagenumberbox%
]{chapter,section,subsection,subsubsection}

\RedeclareSectionCommand[%
    ,beforeskip=1.15em plus 1pt%
    ,tocentryformat=\textbf%
    ,toclinefill={\TOCLineLeaderFill[\textbf{.}]}%
]{chapter}
\RedeclareSectionCommand[%
  ,tocindent=3.38em%
]{subsection}
\RedeclareSectionCommand[%
  ,tocindent=6.38em%
]{subsubsection}


\DeclareTOCStyleEntry[%
    ,dynnumwidth=true%
    ,numwidth=0pt%
    ,numsep=\skillmon@numsep%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{table}
\DeclareTOCStyleEntry[%
    ,dynnumwidth=true%
    ,numwidth=0pt%
    ,numsep=\skillmon@numsep%
    ,pagenumberbox=\skillmon@pagenumberbox%
]{tocline}{figure}
\makeatother

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\blinddocument
\addxcontentsline{lot}{table}[1.1]{example of table}
\addxcontentsline{lot}{table}[1.2]{example of table}
\addxcontentsline{lof}{figure}[1.1]{example of figure}
\addxcontentsline{lof}{figure}[1.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[2.1]{example of table}
\addxcontentsline{lot}{table}[2.2]{example of table}
\addxcontentsline{lof}{figure}[2.1]{example of figure}
\addxcontentsline{lof}{figure}[2.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[3.1]{example of table}
\addxcontentsline{lot}{table}[3.2]{example of table}
\addxcontentsline{lof}{figure}[3.1]{example of figure}
\addxcontentsline{lof}{figure}[3.2]{example of figure}
\end{document}

I have removed the options with values equal to the defaults. Run three times to get the same result as above.


Because \CloneTOCEntryStyle is mentioned in the question:

scrreprt uses \CloneTOCEntryStyle to clone tocline to the styles chapter and section and \TOCEntryStyleStartInitCode to declare the initial settings for some of the options of the new styles. Then style section is cloned to style default.

So you could also do something like (warning: the example below uses undocumented internal commands, so it can break in the future)

\documentclass[fontsize=11pt,
%listof=nochaptergap% remove the chapter gap in lists like LOT or LOF
]{scrreprt}[2017/01/03]

\usepackage[left=25mm,right=25mm,top=8.4mm,bottom=10.7mm%
    ,includeheadfoot,headsep=15.4mm,marginparwidth=18mm,marginparsep=4mm]%
    {geometry}

\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

\usepackage{blindtext}

\makeatletter
\def\@dotsep{0.072}

\TOCEntryStyleInitCode{default}{%
    \expandafter\renewcommand%
        \csname scr@tso@#1@numwidth\endcsname{0pt}%
    \expandafter\renewcommand%
        \csname scr@tso@#1@numsep\endcsname{0pt}%
  \expandafter\renewcommand%
      \csname scr@tso@#1@pagenumberbox\endcsname[1]{\makebox{##1}}%
}
\makeatother

\RedeclareSectionCommands[tocstyle=default,tocdynnumwidth=true]{chapter,section,subsection,subsubsection}
\DeclareTOCStyleEntry[dynnumwidth=true]{default}{table}
\DeclareTOCStyleEntry[dynnumwidth=true]{default}{figure}

\RedeclareSectionCommand[%
    ,beforeskip=1.15em plus 1pt%
    ,tocentryformat=\textbf%
    ,toclinefill={\TOCLineLeaderFill[\textbf{.}]}%
]{chapter}
\RedeclareSectionCommand[%
  ,tocindent=6.38em%
]{subsection}

\begin{document}
\tableofcontents
\listoftables
\listoffigures
\blinddocument
\addxcontentsline{lot}{table}[1.1]{example of table}
\addxcontentsline{lot}{table}[1.2]{example of table}
\addxcontentsline{lof}{figure}[1.1]{example of figure}
\addxcontentsline{lof}{figure}[1.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[2.1]{example of table}
\addxcontentsline{lot}{table}[2.2]{example of table}
\addxcontentsline{lof}{figure}[2.1]{example of figure}
\addxcontentsline{lof}{figure}[2.2]{example of figure}
\blinddocument
\addxcontentsline{lot}{table}[3.1]{example of table}
\addxcontentsline{lot}{table}[3.2]{example of table}
\addxcontentsline{lof}{figure}[3.1]{example of figure}
\addxcontentsline{lof}{figure}[3.2]{example of figure}
\end{document}
12
  • Thank you very much for the answer and the explanation why dynnumwidth doesn't work. If there is the possibility that the method breaks in the future, I think I'll just use my code with the tweaks you provided. Thank you very much!
    – Skillmon
    Jun 10, 2017 at 10:52
  • 1
    You are welcome. The first example (without internal commands) should work in the future. The second if only shown because you have mentioned \CloneTOCEntryStyle in the question.
    – esdd
    Jun 10, 2017 at 10:59
  • If it sets the minimum width, shouldn't it have an effect only if the numbers are shorter? If it has an effect only if they are longer, wouldn't that mean it is setting their maximum width?
    – cfr
    Jun 10, 2017 at 12:45
  • @esdd I had to drop the usage of \RedeclareSectionCommands, because I have to use titlesec for some formattings of headings. But now everything is working in my code.
    – Skillmon
    Jun 10, 2017 at 14:14
  • 1
    @Skillmon The usage of titlesec with a KOMA-Script class is not recommended. It breaks some KOMA features. Maybe it can replaced by redefinitions of \chapterlinesformat etc.
    – esdd
    Jun 10, 2017 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .