I have a long document which uses the KOMA-Script book class scrbook
and I would like to add a section-level table of contents to a few rather long sections in my document. I am already using the minitoc
package to provide part TOCs. The minitoc package also has a secttoc
command, but this cannot be used along with the book class.
I have already tried using the etoc
package, with the following code:
\section{My Section}
\etocsettocstyle{}{}
\etocsetnexttocdepth{3}
\localtableofcontents*
however, this seems to conflict with something in either minitoc
or scrbook
and didn't work.
Other resources seem to indicate that I might be able to use the built in tocbasic
which is part of KOMA-Script, but I was not able to figure out how that would work from the documentation.
MWE:
\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}
Best Answer
If you need such a section table of contents only for a few section (or if you use
lualatex
that does not have TeX's file handle restrictions) you could indeed usetocbasic
. Add this to the end of your preamble:Then use
\sectiontoc
right after the\section
that should have a section toc. This will produce, e.g.,Note: You cannot use
\sectiontoc
for not numbered section, e.g., made by\addsec
or\section*
. If you need such section ToCs, you cannot use\thesection
for the file extension.