在已经使用 minitoc 的 KOMA 脚本文档中创建节级目录

在已经使用 minitoc 的 KOMA 脚本文档中创建节级目录

我有一篇很长的文档,它使用了 KOMA-Script 书籍类scrbook,我想为文档中几个相当长的章节添加一个章节级目录。我已经使用该minitoc包来提供部分目录。minitoc 包也有一个secttoc命令,但它不能与书籍类一起使用。

我已经尝试使用该etoc包,代码如下:

\section{My Section}
\etocsettocstyle{}{}
\etocsetnexttocdepth{3}
\localtableofcontents*

然而,这似乎与或中的某些内容相冲突,minitoc并且scrbook不起作用。

其他资源似乎表明我可能能够使用内置的tocbasicKOMA-Script 部分,但我无法从文档中弄清楚它如何工作。

梅威瑟:

\documentclass{scrbook}

%%% Language support %%%
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{lipsum} % For MWE

\setcounter{secnumdepth}{3} % makes subsubsections numbered

%%% TOC custimization %%%
\usepackage{minitoc}
\setcounter{tocdepth}{-1} % only includes parts and chapters (not sections) in main TOC
\mtcsetdepth{parttoc}{1} % only includes chapters and sections (not subsections) in part TOCs

\usepackage[tocindentauto]{tocstyle} % prettier TOC
\usetocstyle{allwithdot} %use 'KOMAlike" if you don't want dots

\mtcsettitle{parttoc}{Contents} %renames the part TOC to match main TOC

\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}


\begin{document}
\doparttoc

\begin{titlepage}
\centering
\ \\
\vspace{5cm}
{\Huge Title}
\end{titlepage}

\thispagestyle{empty}
\tableofcontents


\mainmatter
\part{Part 1}
\parttoc
\chapter{Chapter 1}
\section{Section 1.1}
%insert Sect TOC HERE
\lipsum
  \subsection{Sub Sec 1.1.1}
  \lipsum
    \subsubsection{Sub Sub Sec 1.1.1.1}
    \lipsum
    \subsubsection{Sub Sub Sec 1.1.1.2}
    \lipsum
    \subsubsection{Sub Sub Sec 1.1.1.3}
    \lipsum
  \subsection{Sub Sec 1.1.2}
  \lipsum
  \subsection{Sub Sec 1.1.3}
  \lipsum
  \subsection{Sub Sec 1.1.4}
  \lipsum
    \subsubsection{Sub Sub Sec 1.1.4.1}
    \lipsum
    \subsubsection{Sub Sub Sec 1.1.4.2}
    \lipsum
    \subsubsection{Sub Sub Sec 1.1.4.3}
    \lipsum
  \subsection{Sub Sec 1.1.5}
  \lipsum
\section{Section 1.2}

\chapter{Chapter 2}
\lipsum

\part{Part 2}
\parttoc
\chapter{Chapter 3}
\lipsum

\end{document}

答案1

如果你只需要为几个部分添加这样的目录(或者如果你使用lualatex不受 TeX 文件句柄限制的目录),你确实可以使用tocbasic。将其添加到序言的末尾:

\makeatletter
\newif\ifusesectiontoc% Switch to tell \addtocentrydefault to not only make entries to the toc-file but also to the current section-toc-file
\newcommand*{\sectiontoc}{% new command to generate and show a section toc
  \usesectiontoctrue% switch on section-toc-entries
  \edef\ext@subtoc{toc\thesection}% extension of the section-toc-file, e.g., toc1.1
  \expandafter\DeclareNewTOC\expandafter{\ext@subtoc}% declare a new toc file
  \begin{minipage}{.9\linewidth}
    \value{tocdepth}=\subsectiontocdepth% we want entries down to subsection
    \expandafter\listoftoc\expandafter*\expandafter{\ext@subtoc}% show the toc without any heading
  \end{minipage}\par
  \bigskip\noindent% add some vertical space after the toc and do not indent the following text
}
\usepackage{xpatch}
\xapptocmd\addtocentrydefault{% patch the KOMA-Script's generic toc entry generator
  \ifusesectiontoc% if section toc entries should be generated
    \expandafter\tocbasic@addxcontentsline\expandafter{\ext@subtoc}{#1}{#2}{#3}% do it
  \fi
}{}{}
\xpretocmd\section{\usesectiontocfalse}{}{}% automatically switch of section toc entries at start of every \section
\makeatother

然后在应该有一个 toc 部分的\sectiontoc后面使用。这将产生,例如,\section

在此处输入图片描述

注意:您不能将其用作\sectiontoc未编号的部分,例如由\addsec或制作\section*。如果您需要此类部分目录,则不能将其用作\thesection文件扩展名。

答案2

我简要地查看了 的用法etoc。主要障碍是 KOMA、tocbasic 或 minitoc 之一定义了xpart未知的分段级别etoc。最简单的用法是忽略etoc它(它似乎总是遵循parttoc 文件中的一行,因此etoc即使忽略 也仍然知道本地 TOC 应该在何处结束xpart)并防止etoc重新定义\tableofcontents

\let\withoutetoctableofcontents\tableofcontents
\usepackage{etoc}
\etocsetlevel{xpart}{6}% makes xpart invisible to etoc
\let\tableofcontents\withoutetoctableofcontents

\begin{document}

然后,您可以通过etoc以下方式执行本地目录,例如:

\section{Section 1.1}

\etocsetnexttocdepth{3}
\etocsettocstyle{}{}
\localtableofcontents


\lipsum

这样修改了您的示例(请注意,有一个注释

\setcounter{tocdepth}{-1} % only includes parts and chapters (not sections) in main TOC

在我看来这不对,它不应该,0或者-1至少在book课堂上应该是,也许 KOMA 是不同的)

\documentclass{scrbook}

%%% Language support %%%
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{lipsum} % For MWE

\setcounter{secnumdepth}{3} % makes subsubsections numbered

%%% TOC custimization %%%
\usepackage{minitoc}
\setcounter{tocdepth}{-1} % only includes parts and chapters (not sections) in main TOC
\mtcsetdepth{parttoc}{1} % only includes chapters and sections (not subsections) in part TOCs

\usepackage[tocindentauto]{tocstyle} % prettier TOC
\usetocstyle{allwithdot} %use 'KOMAlike" if you don't want dots

\mtcsettitle{parttoc}{Contents} %renames the part TOC to match main TOC

\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}

\let\withoutetoctableofcontents\tableofcontents
\usepackage{etoc}
\etocsetlevel{xpart}{6}
\let\tableofcontents\withoutetoctableofcontents

\begin{document}
\doparttoc

\begin{titlepage}
\centering
\ \\
\vspace{5cm}
{\Huge Title}
\end{titlepage}

\thispagestyle{empty}
\tableofcontents


\mainmatter
\part{Part 1}
\parttoc
\chapter{Chapter 1}
\section{Section 1.1}

\etocsetnexttocdepth{3}
\etocsettocstyle{}{}
\localtableofcontents


\lipsum
  \subsection{Sub Sec 1.1.1}
  \lipsum
    \subsubsection{Sub Sub Sec 1.1.1.1}
    \lipsum
    \subsubsection{Sub Sub Sec 1.1.1.2}
    \lipsum
    \subsubsection{Sub Sub Sec 1.1.1.3}
    \lipsum
  \subsection{Sub Sec 1.1.2}
  \lipsum
  \subsection{Sub Sec 1.1.3}
  \lipsum
  \subsection{Sub Sec 1.1.4}
  \lipsum
    \subsubsection{Sub Sub Sec 1.1.4.1}
    \lipsum
    \subsubsection{Sub Sub Sec 1.1.4.2}
    \lipsum
    \subsubsection{Sub Sub Sec 1.1.4.3}
    \lipsum
  \subsection{Sub Sec 1.1.5}
  \lipsum
\section{Section 1.2}

\chapter{Chapter 2}
\lipsum

\part{Part 2}
\parttoc
\chapter{Chapter 3}
\lipsum

\end{document}

相关内容