5

I have a long document which uses the KOMA-Script book class scrbook and I would like to add a part-level and chapter-level table of contents, as it is shown on figures below:

Chapter-level TOC in twocolumn page layout

It works, but KOMA complains about many things:

1. Issue: KOMA-Script together with Minitoc package

(scrbook)              with a KOMA-Script class is not recommended.
(scrbook)              Nevertheless, using requested
(scrbook)              package `minitoc' on input line 67

2. Issue \bprot@dottedtocline

Class scrbook Warning: usage of `\bprot@dottedtocline' is deprecated.

Can be replaced code below with KOMA-script possibilites, so it would be possible to remove package minitoc from project?

MWE:

\documentclass[open=any, titlepage=false, twocolumn, fontsize=10pt,]{scrbook}

  \usepackage[showframe]{geometry}
  \usepackage{blindtext}
  % ===========================
  %    My KOMA setting 
  % ===========================
  % http://tex.stackexchange.com/questions/51867/
   \usepackage{scrhack}                      % KOMA warning about ToC
   \usepackage{xcolor}

  % ---- Part -----------------------------------------------------
  % https://tex.stackexchange.com/questions/102303/
  % https://tex.stackexchange.com/questions/110092/
    \newcommand*\partcolor{\color{blue}}% Part is coloured blue
    \renewcommand*\partformat    
      {\partcolor\partname~\thepart\if@altsecnumformat.\fi}

  % Adjusting spacing around section subsection titles with koma script
  % https://tex.stackexchange.com/questions/223508/
  % https://tex.stackexchange.com/questions/43087/
    \RedeclareSectionCommand[
      beforeskip=-1sp,
      afterskip=2\baselineskip
    ]{chapter}

   \RedeclareSectionCommand[
     beforeskip=-\baselineskip,
     afterskip=.5\baselineskip
   ]{section}

  \RedeclareSectionCommand[
    beforeskip=-.75\baselineskip,
    afterskip=.5\baselineskip
  ]{subsection}

 \RedeclareSectionCommand[
   beforeskip=-.5\baselineskip,
   afterskip=.25\baselineskip
 ]{subsubsection}


 % Table fo content  TOC   
 % ---------------------     
 % the tocbasic package style selected and configured with DeclareTOCStyleEntry
 \KOMAoptions{toc=chapterentrydotfill}

\DeclareTOCStyleEntry[%
  dynnumwidth=true,%
   % numwidth=3.5em, 
       indent=3em, 
   beforeskip=1em
]{tocline}{part} % scrguien page 357

\DeclareTOCStyleEntry[
  dynnumwidth=true,
   % numwidth=2em, 
   beforeskip=1em
]{tocline}{chapter}

% ---- Table fo content for each chapter------------
% minitoc.pdf: If used, the hyperref package must be loaded before minitoc. 
% https://tex.stackexchange.com/questions/334007
% https://tex.stackexchange.com/questions/268205
% https://tex.stackexchange.com/questions/167390
% https://tex.stackexchange.com/questions/164308/
\let\cleardoublepage=\clearpage  % Remove blank page after TOC and title page
\usepackage[nohints,tight]{minitoc}   % formatting table of contents.
  \mtcsettitle{minitoc}{ }        % sets title or empty title (i.e. no title)
  \mtcsettitle{parttoc}{Obsah} 
  % Vertical gap before part-level mini-tables titles. Default: 50pt
  \renewcommand\mtcgapbeforeheads{0pt}  
  % Vertical gap after part-level mini-tables titles. Default: 40pt   
  \renewcommand\mtcgapafterheads{0pt}
 \mtcsetrules{minitoc}{off}           
 \mtcsetoffset{minitoc}{-0.5em}
 \setlength{\mtcindent}{-0.5em}           % sets the indentation of the toc
 \mtcsetfeature{minitoc}{open}{\vspace{1mm}}

% onecolumn table of contents & minitoc in twocolumn document:
% https://tex.stackexchange.com/questions/151320/
\newcommand{\dochaptertoc}{%
  \vspace{-1.5\baselineskip} % workaround for removed rule
  \smash{\makebox[\linewidth]{\hrulefill}} % workaround for removed rule
  \vspace{-2.5\baselineskip} % workaround for removed rule
  \minitoc
  \vspace{-1.15\baselineskip} % workaround for removed rule
  \smash{\makebox[\linewidth]{\hrulefill}} % workaround for removed rule
  \vspace{-0.5\baselineskip} % workaround for removed rule
}

\newcommand{\setchaptertoc}{%
  \setchapterpreamble{% KOMA-Script command 
  \dochaptertoc%
  }
}  
% The KOMA -Script package tocstyle
% -------------------------------------
% How to increase the numwidth for a part in ToC?
% https://tex.stackexchange.com/questions/119849/
% https://tex.stackexchange.com/questions/63856/
% With option tocindentauto all widths at the TOCs are calc. by tocstyle.
\usepackage[tocindentauto, tocgraduated]{tocstyle}
\usetocstyle{KOMAlike}

\makeatletter
  \renewcommand*{\raggedchapterentry}{\setlength{\@tempdima}{3em}}
  \renewcommand*\l@part{\bprot@dottedtocline{-1}{1.5em}{4.5em}}
  \renewcommand*\l@section{\bprot@dottedtocline{1}{1.5em}{3.5em}}
  \renewcommand*\l@subsection{\bprot@dottedtocline{2}{3.8em}{4em}}
  \renewcommand*\l@subsubsection{\bprot@dottedtocline{3}{7.0em}{4.1em}}
  \renewcommand*\l@paragraph{\bprot@dottedtocline{4}{10em}{5em}}
  \renewcommand*\l@subparagraph{\bprot@dottedtocline{5}{12em}{6em}}
  \def\@pnumwidth{3em}  % default 1.55
\makeatother

\begin{document}
\setcounter{tocdepth}{-1} % 
\setcounter{secnumdepth}{4}           % Number subsubsections in the chapters
\setcounter{parttocdepth}{0} 
\doparttoc
\setcounter{minitocdepth}{2} 
\dominitoc
\tableofcontents

\setcounter{page}{3000}  
\setcounter{chapter}{100}
\setcounter{part}{5080}

\setchaptertoc 

\part{Part I}
\parttoc
  \chapter{My chapter I}
    \section{My first section}  
      \blindtext
        \subsection{My first subsection}
          \blindtext  
    \section{My second section}
        \blindtext 
  \chapter{My chapter II}
  \chapter{My chapter II}
  \chapter{My chapter III}
  \chapter{My chapter IV}
  \chapter{My chapter V}
  \chapter{My chapter VI}
  \chapter{My chapter VII}
  \chapter{My chapter VIII}
  \chapter{My chapter IX}
  \chapter{My chapter X}
  \chapter{My chapter XI}
  \chapter{My chapter XII}
  \chapter{My chapter XIII}
  \chapter{My chapter XIV}
  \chapter{My chapter XV}
  \chapter{My chapter XVI}
  \chapter{My chapter XVII}
  \chapter{My chapter XVIII}
  \chapter{My chapter XIX}
  \chapter{My chapter XX}
  \chapter{My chapter XXI}
  \chapter{My chapter XXII}
  \chapter{My chapter XXIII}
  \chapter{My chapter XXIV}
  \chapter{My chapter XXVI}
  \chapter{My chapter XXVII}
  \chapter{My chapter XXVIII}
  \chapter{My chapter XXIX}
  \chapter{My chapter XXX}
\part{Part II}
\parttoc
  \chapter{My chapter I}
    \section{My first section}  
      \blindtext
        \subsection{My first subsection}
            \blindtext  
    \section{My second section}
        \blindtext 
\end{document}
2
  • Remove package tocstyle from your code. Replace the \bprot@dottedtocline code using either \RedeclareSectionCommand or \DeclareTOCStyleEntry. Maybe package etoc can be used to get local ToCs in chapters and parts. – esdd Nov 13 '19 at 14:31
  • @esdd No solution with tocbasic package? I found komascript.de/node/2107, but I don't understand it. – Keks Dose Nov 13 '19 at 17:34
2

Here is a suggestion that bases on the answer of @Schweinebacke to Create section-level toc in a KOMA-script document that already uses minitoc and on my answer to How to write a minitoc with plain KOMA-script? It needs at least KOMA-Script version 3.27 (provides hooks which can be used by \AddtoOneTimeDoHook or \AddtoDoHook).

\documentclass[fontsize=10pt,open=any,twocolumn]{scrbook}[2019/10/12]% needs version 3.27 or newer
\providecommand*{\Ifstr}{\ifstr}% added because of changes in upcoming KOMA-Script version 3.28 and \ifstr replaced by \Ifstr in the code (see https://komascript.de/faq_deprecatedif) 
\usepackage{blindtext}
\usepackage{xcolor}

\usepackage{scrwfile}% avoid trouble with the limited number of write handles
\usepackage{xpatch}

\colorlet{partcolor}{blue}
\addtokomafont{partprefix}{\color{partcolor}}% change color of part prefix
\addtokomafont{part}{\normalcolor}% use normal color for part title
%\renewcommand*\partformat{\partname~\thepart}% if you want to remove \autodot from the definition
\RedeclareSectionCommand[
  tocdynnumwidth=true,%
  tocbeforeskip=1em,
  tocindent=1.5em
]{part}
\RedeclareSectionCommand[
  beforeskip=0pt,
  afterindent=false,
  afterskip=2\baselineskip,
  tocdynnumwidth,
  tocbeforeskip=1em plus 1pt minus 1pt,% add some glue
  toclinefill=\TOCLineLeaderFill
]{chapter}
\RedeclareSectionCommand[
  beforeskip=\baselineskip,
  afterindent=false,
  afterskip=.5\baselineskip,
  tocindent=1.5em,
  tocnumwidth=3.5em
]{section}
\RedeclareSectionCommand[
  beforeskip=.75\baselineskip,
  afterindent=false,
  afterskip=.5\baselineskip,
  tocindent=3.8em,
  tocnumwidth=4em
]{subsection}
\RedeclareSectionCommand[
  beforeskip=.5\baselineskip,
  afterindent=false,
  afterskip=.25\baselineskip,
  tocindent=7em,
  tocnumwidth=4.1em
]{subsubsection}
\RedeclareSectionCommand[
  tocindent=10em,
  tocnumwidth=5em
]{paragraph}
\RedeclareSectionCommand[
  tocindent=12em,
  tocnumwidth=6em
]{subparagraph}

\RedeclareSectionCommands
  [tocpagenumberwidth=3em]
  {part,chapter,section,subsection,paragraph,subparagraph}

% https://tex.stackexchange.com/a/359758
% https://tex.stackexchange.com/a/502077
\makeatletter
\newif\ifuseparttoc
\newcommand*{\parttoc}[1][\thepart]{% new command to generate and show a chapter toc
  \useparttoctrue% switch on part-toc-entries
  \edef\ext@parttoc{tcp#1}% extension of the part-toc-file, e.g., tcpI
  \DeclareNewTOC[
    listname=Obsah,
    %unset=onecolumn% if the part toc should use twocolumn
  ]{\ext@parttoc}% declare a new toc file
  \begingroup
    \value{tocdepth}=\chaptertocdepth% we want entries down to chapter
    \listoftoc{\ext@parttoc}% show the toc with header
  \endgroup
}
\xapptocmd\addtocentrydefault{% patch the KOMA-Script's generic toc entry generator
  \ifuseparttoc% if part toc entries should be generated
    \expandafter\tocbasic@addxcontentsline\expandafter{\ext@parttoc}{#1}{#2}{#3}% do it
  \fi
}{}{}
\xpretocmd\part{\useparttocfalse}{}{}% entries in part toc are automatically switched off at start of \part
\newif\ifusechaptertoc% Switch to tell \addtocentrydefault to not only make entries to the toc-file but also to the current section-toc-file
\newcommand*{\chaptertoc}[2][\thechapter]{% new command to generate and show a chapter toc
  \usechaptertoctrue% switch on chapter-toc-entries
  \edef\ext@chaptoc{tcc#1}% extension of the chapter-toc-file, e.g., tcc1
  \DeclareNewTOC{\ext@chaptoc}% declare a new toc file
  %\addsec*{Contents}% header of the chaptertoc
  \setchapterpreamble{%
    \begin{minipage}{\linewidth}
      \hrulefill\par
      \value{tocdepth}=\subsectiontocdepth% we want entries down to subsection
      \listoftoc*{\ext@chaptoc}% show the toc without header
    \end{minipage}%
    \par\bigskip\nobreak\noindent\hrulefill\par
    \bigskip\noindent\ignorespaces% add some vertical space after the toc and do not indent the following text
  }%
}
\xapptocmd\addtocentrydefault{% patch the KOMA-Script's generic toc entry generator
  \ifusechaptertoc% if chapter toc entries should be generated
    \Ifstr{#1}{chapter}{}
      {\expandafter\tocbasic@addxcontentsline\expandafter{\ext@chaptoc}{#1}{#2}{#3}}% do it
  \fi
}{}{}
\xpretocmd\chapter{\usechaptertocfalse}{}{}% entries in chapter toc are automatically switched off at start of \chapter
\xpretocmd\part{\usechaptertocfalse}{}{}% entries in chapter toc are automatically switched off at start of \part
\makeatother

\newcommand\setchaptertoc[1][]{%
  \Ifstr{#1}{}
    {\AddtoOneTimeDoHook{heading/preinit/chapter}{\chaptertoc}}
    {\AddtoOneTimeDoHook{heading/preinit/chapter}{\chaptertoc[#1]}}%
}

\setcounter{tocdepth}{\partnumdepth}% depth of TOC
\begin{document}
\tableofcontents

\setcounter{page}{3000}
\setcounter{chapter}{100}
\setcounter{part}{5080}

\part{Part I}
\parttoc

\setchaptertoc
\chapter{My chapter I}
\section{My first section}
\blindtext
\subsection{My first subsection}
\blindtext
\section{My second section}
\blindtext

\chapter{My chapter II}
\chapter{My chapter II}
\chapter{My chapter III}
\chapter{My chapter IV}
\chapter{My chapter V}
\chapter{My chapter VI}
\chapter{My chapter VII}
\chapter{My chapter VIII}
\chapter{My chapter IX}
\chapter{My chapter X}
\chapter{My chapter XI}
\chapter{My chapter XII}
\chapter{My chapter XIII}
\chapter{My chapter XIV}
\chapter{My chapter XV}
\chapter{My chapter XVI}
\chapter{My chapter XVII}
\chapter{My chapter XVIII}
\chapter{My chapter XIX}
\chapter{My chapter XX}
\chapter{My chapter XXI}
\chapter{My chapter XXII}
\chapter{My chapter XXIII}
\chapter{My chapter XXIV}
\chapter{My chapter XXVI}
\chapter{My chapter XXVII}
\chapter{My chapter XXVIII}
\chapter{My chapter XXIX}
\chapter{My chapter XXX}

\part{Part II}
\parttoc
\setchaptertoc
\chapter{My chapter I}
\section{My first section}
\blindtext
\subsection{My first subsection}
  \blindtext
\section{My second section}
\blindtext
\end{document}

Additional remark: I have used your settings in e.g. \l@section for the tocindents and tocnumwidths. But I think, you have to adjust them, if you change tocdepth for the chapter tocs to e.g. \subsubsectiontocdepth.

Result:

enter image description here

1
  • 1
    You are »incroyable«. – Keks Dose Nov 14 '19 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.