0

I just trying to create TOC for every chapter. Therefore I created a command \setchaptertoc according to the question 517733. The problem appears when chapter contains too much section. In that case the TOC overfull the page, and it is not continued in next page. I try to use tcolorbox package instead of minipage. The compilation result is shown in figure below.

I also look on question "How to make minipage spanning multiple pages", where breakable tcolorbox environment is used.

I am using Lualatex and package scrwfile, so I am not restricted with @writefile for toc.

enter image description here

MNWE

\documentclass[fontsize=10pt,open=any,twocolumn]{scrbook}[2019/10/12]% needs version 3.27 or newer
    \usepackage{blindtext}
    \usepackage{scrwfile}% avoid trouble with the limited number of write handles
    \usepackage{xpatch}
    \usepackage[skins,breakable]{tcolorbox}

% https://tex.stackexchange.com/a/359758 % https://tex.stackexchange.com/a/502077 % https://tex.stackexchange.com/questions/516093 % https://tex.stackexchange.com/questions/430594/use-minitoc-with-koma-script-scrbook/502856 \makeatletter

\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{tcolorbox}[breakable] % \hrulefill\par \value{tocdepth}=\subsectiontocdepth % we want entries down to subsection \listoftoc*{\ext@chaptoc} % show the toc without header \end{tcolorbox}% \par\nobreak\noindent\hrulefill\par % \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}{}{} % automatically switch of chapter toc entries at start % of every \chapter \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

\part{My Part I}

\setchaptertoc \chapter{My chapter I} \section{My first section} \blindtext \subsection{My 1th subsection} \blindtext \subsection{My 2nd subsection} \blindtext \subsection{My 3rd subsection} \blindtext \subsection{My 4th subsection} \blindtext \subsection{My 5th subsection} \blindtext \subsection{My 6th subsection} \blindtext \subsection{My 7th subsection} \blindtext \subsection{My 8th subsection} \blindtext \subsection{My 9th subsection} \blindtext \subsection{My 10th subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext \section{My second section} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext
\subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext
\section{My third section} \blindtext \subsection{My first subsection} \blindtext \subsection{My second subsection} \blindtext
\subsection{My third subsection} \blindtext \subsection{My fourth subsection} \blindtext
\section{My fourth section} \blindtext \subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext
\subsection{My first subsection} \blindtext \subsection{My first subsection} \blindtext
\section{My fifth section} \blindtext \subsection{My first subsection} \blindtext \subsection{My second subsection} \blindtext
\subsection{My third subsection} \blindtext \subsection{My fourth subsection} \blindtext
\section{My sixth section} \blindtext \subsection{My first subsection} \blindtext \subsection{My second subsection} \blindtext
\subsection{My third subsection} \blindtext \subsection{My fourth subsection} \blindtext
\section{My seventh section} \blindtext \subsection{My first subsection} \blindtext \subsection{My second subsection} \blindtext
\subsection{My third subsection} \blindtext \subsection{My fourth subsection} \blindtext
\end{document}

JardaFait
  • 3,922

1 Answers1

1

I think we can use the minitoc package to get a toc per chapter. The strip environment defined in the cuted package is used here to make the minitoc take all the page width in a two columns document.

\documentclass[fontsize=10pt,open=any,twocolumn]{scrbook}[2019/10/12]% needs version 3.27 or newer
    \usepackage{blindtext}
\usepackage{minitoc,cuted}
\dominitoc

\setcounter{tocdepth}{\partnumdepth}% depth of TOC

\begin{document} \tableofcontents

\part{My Part I}

%\setchaptertoc \chapter{My chapter I}

\begin{strip}
\minitoc
\end{strip}
    \section{My first section}
        \blindtext
    \subsection{My 1th subsection}
        \blindtext
    \subsection{My 2nd subsection}
        \blindtext
    \subsection{My 3rd subsection}
        \blindtext
    \subsection{My 4th subsection}
        \blindtext
    \subsection{My 5th subsection}
        \blindtext
    \subsection{My 6th subsection}
        \blindtext
    \subsection{My 7th subsection}
        \blindtext
    \subsection{My 8th subsection}
        \blindtext
    \subsection{My 9th subsection}
        \blindtext
    \subsection{My 10th subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext
\section{My second section}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext     
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext    
\section{My third section}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My second subsection}
        \blindtext     
    \subsection{My third subsection}
        \blindtext
    \subsection{My fourth subsection}
        \blindtext       
\section{My fourth section}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext     
    \subsection{My first subsection}
        \blindtext
    \subsection{My first subsection}
        \blindtext    
\section{My fifth section}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My second subsection}
        \blindtext     
    \subsection{My third subsection}
        \blindtext
    \subsection{My fourth subsection}
        \blindtext  
\section{My sixth section}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My second subsection}
        \blindtext     
    \subsection{My third subsection}
        \blindtext
    \subsection{My fourth subsection}
        \blindtext    
\section{My seventh section}
        \blindtext
    \subsection{My first subsection}
        \blindtext
    \subsection{My second subsection}
        \blindtext     
    \subsection{My third subsection}
        \blindtext
    \subsection{My fourth subsection}
        \blindtext           

\end{document}

enter image description here

enter image description here

  • 1
    I tested your code. I received the error: chapter 1. (grain0073a.mtc1) ! Undefined control sequence. @outputdblcol ...i @combinedblfloats @setmarks @outputpage \begingroup ... l.26 \end{strip} First compilation was fine, but the second not. Also usage minitoc together with komascript is deprecated. – JardaFait Feb 12 '22 at 17:55
  • 1
    @JardaFait . This seams weird to me because I have tested the code on overleaf with luatex engine and I get no errors! – Hafid Boukhoulda Feb 12 '22 at 18:43