我试图将 toc 和 etoc 的深度设置为不同的值,但似乎无法解决。的深度etoc
遵循的深度toc
。以下是 MWE:
\documentclass[
10=2pt, % The default document font size, options: 10pt, 11pt, 12pt
%oneside, % Two side (alternating margins) for binding by default, uncomment to switch to one side
english, % ngerman for German
singlespacing, % Single line spacing, alternatives: onehalfspacing or doublespacing
%draft, % Uncomment to enable draft mode (no pictures, no links, overfull hboxes indicated)
%nolistspacing, % If the document is onehalfspacing or doublespacing, uncomment this to set spacing in lists to single
liststotoc, % Uncomment to add the list of figures/tables/etc to the table of contents
toctotoc, % Uncomment to add the main table of contents to the table of contents
parskip, % Uncomment to add space between paragraphs
nohyperref, % Uncomment to not load the hyperref package
headsepline, % Uncomment to get a line under the header
%chapterinoneline, % Uncomment to place the chapter title next to the number on one line
%consistentlayout, % Uncomment to change the layout of the declaration, abstract and acknowledgements pages to match the default layout
]{MastersDoctoralThesis} % The class file specifying the document structure
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage{ragged2e}
\usepackage{booktabs,multirow}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta,fit,matrix,shapes,positioning,decorations.pathreplacing,calc,calligraphy,shadows}
\usepackage{svg}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{xcolor}
\usepackage{csquotes}
\usepackage{color}
\usepackage{colortbl}
\definecolor{darkgreen}{RGB}{0,100,0}
\definecolor{khrawi2}{RGB}{220,200,90}
\definecolor{khrawi}{RGB}{85,34,0}
\definecolor{yellow}{RGB}{255,255,0}
\definecolor{noir}{RGB}{0,0,0}
\definecolor{gray}{RGB}{200,51,51}
\definecolor{mapink}{RGB}{255,169,169}
\definecolor{mablue}{RGB}{33,190,208}
\definecolor{hotpink}{RGB}{255,105,180}
\colorlet{linkequation}{darkgreen}
\usepackage{enumitem}
\usepackage{nicematrix}
\usepackage{subcaption}
\captionsetup[subfigure]{labelfont=rm}
\usepackage{circuitikz}
\usepackage{lettrine}
\usepackage{geometry}
\usepackage{amssymb}
\usepackage{asymptote}
\usepackage{mathtools}
\usepackage{etoc}
\usepackage{xfrac}
\usepackage{nicefrac}
\usepackage{subcaption}
\usepackage{bigdelim}
\usepackage{datetime}
\usepackage{slashbox}
\usepackage{scalefnt}
\usepackage{float}
\usepackage{tocloft}
\usepackage{mathpazo} % Use the Palatino font by default
\usepackage[style=ieee,backend=bibtex]{biblatex}
\usepackage{lipsum}
\begin{document}
% \setcounter{tocdepth}{4}
% \etocsettocdepth{3}
\tableofcontents
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\chapter{chapter}
\etocsettocdepth{1}
\localtableofcontents
\section{1}
\section{2}
\chapter{chapter}
\etocsettocdepth{1}
\localtableofcontents
\section{1}
\subsection{test}
a
\section{2}
b
\subsection{121}
c
\subsection{122}
e
\subsection{123}
f
\chapter{chapter}
\etocsettocdepth{4}
\localtableofcontents
\section{1}
\subsection{21}
\section{2}
\subsection{22}
\subsubsection{22}
\end{document}
答案1
线路
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
导致了您所看到的情况。它对文件内部设置为 1 的 tocdepth 进行硬编码,.toc
因此会影响版本的所有\tableofcontents
用法etoc
。
尝试这个
\documentclass{report}
\usepackage[T1]{fontenc}
% \usepackage{geometry}
\usepackage{tocloft}% always load before etoc
\usepackage{etoc}
\begin{document}
% better to use \etocsetnexttocdepth to \etocsettocdepth
% (because of hyperref influencing bookmarks according to tocdepth)
% \setcounter{tocdepth}{4}
\etocsetnexttocdepth{2}
\renewcommand{\contentsname}{MAIN TOC (depth 2)}
\tableofcontents
\renewcommand{\contentsname}{Local contents}
% THIS IS COMMENTED OUT ELSE IT MAKES IT IMPOSSIBLE
% TO SHOW ANY SECTIONING DEEPER THAN SECTION
% \addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\chapter{chapter one (TOC with depth 1)}
\etocsetnexttocdepth{1}
\localtableofcontents
\section{1}
a
\subsection{11}
b
\subsection{12}
c
\section{2}
d
\subsection{21}
e
\chapter{chapter two (TOC with depth 2)}
\etocsetnexttocdepth{2}
\localtableofcontents
\section{1}
\subsection{test}
a
\section{2}
b
\subsection{121}
c
\subsection{122}
e
\subsection{123}
f
\chapter{chapter three (TOC with depth 4)}
\etocsetnexttocdepth{4}
\localtableofcontents
\section{1}
\subsection{21}
\section{2}
\subsection{22}
\subsubsection{22}
hello
\paragraph{\TeX} world
\end{document}
你至少需要两个汇编