9

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}
Skillmon
  • 60,462

1 Answers1

6

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}
Skillmon
  • 60,462
esdd
  • 85,675
  • 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 '17 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 '17 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 '17 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 '17 at 14:14
  • @cfr numwidth sets a minimum width which is reserved for the numbers. If the numbers are longer than that and dynnumwidth=false they will overlap with the entries. – Skillmon Jun 10 '17 at 15:18
  • @cfr I have changed my answer a bit. Maybe it is now clearer. – esdd Jun 10 '17 at 20:57
  • 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 '17 at 20:59
  • @Skillmon That sounds like a maximum width to me i.e. no more space is permitted, so longer numbers overlap. A minimum width would create bigger boxes for shorter numbers and let longer numbers have boxes of natural width. – cfr Jun 10 '17 at 22:52
  • @esdd I know that and I would never recommend anybody to use titlesec with KOMA. But for my specific use case (recreating a typographically bad Word template) I found no satisfying solution without titlesec while still using KOMA-script so far (and the rest of it is much easier with KOMA). If you know any solution which allows underlined chapter headings which are line breakable and customizable so I can make them look like the ones I need, please let me know, because I found none (and Markus Kohm states this is bad typography so he won't support it). – Skillmon Jun 11 '17 at 00:18
  • @cfr Without option dynnumwidth=true the value of numwidth is the fixed width for the numbers. But if dynnumwidth=true is set, then numwidth is the minimum space used for the numbers. If at least one number is too long and would overlap the width is adjusted. If they are all shorter then numwidth there is more space between the numbers and titles as numsep and Skillmon wants to remove this white space. – esdd Jun 11 '17 at 06:11
  • @Skillmon Yes it is bad typography. Nevertheless maybe ist is possible (something like https://tex.stackexchange.com/a/256654). But I do not know how the chapter titles should look like. – esdd Jun 11 '17 at 08:40
  • @esdd I never found that solution (and didn't find anything in the scrguide, too). Thank you very much for that link. I'll investigate whether it works for my (really ugly) setup. Again, thank you very much! – Skillmon Jun 11 '17 at 12:24