使用 tcolorbox 和 tocbasic 库在 KOMA 脚本文档中创建节级目录

使用 tcolorbox 和 tocbasic 库在 KOMA 脚本文档中创建节级目录

我只是想为每个章节创建目录。因此我\setchaptertoc根据问题创建了一个命令517733。当章节包含太多部分时,就会出现问题。在这种情况下,目录会溢出页面,并且不会在下一页继续。我尝试使用彩色盒子package,而不是minipage。编译结果如下图所示。

我也看看问题“如何制作跨多个页面的迷你页面",其中使用可破坏的 tcolorbox 环境。

我正在使用 Lualatex 和包 scrwfile,因此我不受 toc 的 @writefile 限制。

在此处输入图片描述

微电子工程协会

\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}

答案1

我认为我们可以使用该minitoc包来获取每个章节的目录。此处使用strip该包中定义的环境cuted来使 minitoc 在两列文档中占据整个页面宽度。

\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}

在此处输入图片描述

在此处输入图片描述

相关内容