我正在使用 MWE 的一部分 如何使用 etoc 包创建本地目录?我想知道如何设置目录深度。
\documentclass{report}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{hyperref}
\titleclass{\part}{top} % make part like a chapter
\titleformat{\part}
[display]
{\centering\normalfont\Huge\bfseries}
{\titlerule[2pt]\vspace{3pt}\titlerule[1pt]\vspace{3pt}\MakeUppercase{\partname} \thepart}
{0pt}
{\titlerule[1pt]\vspace{1pc}\huge\MakeUppercase}
%
\titlespacing*{\part}{0pt}{0pt}{20pt}
\makeatletter
\let\titlesec@part\part
\renewcommand{\part}{\@ifstar\part@star\part@nostar}
\def\part@star#1{\NR@gettitle{#1}\titlesec@part*{#1}}
\def\part@nostar{\@ifnextchar[\part@nostar@opt\part@nostar@nopt}
\def\part@nostar@nopt#1{\NR@gettitle{#1}\titlesec@part{#1}}
\def\part@nostar@opt[#1]#2{\NR@gettitle{#2}\titlesec@part[#1]{#2}}
\makeatother
\begin{document}
\part{FIRST PART}\label{part:one}
\section*{Local toc}
\startcontents[mytoc]
\printcontents[mytoc]{}{0}{}
\chapter{INTRODUCTION} \lipsum{1}
\section{Section 1}
\subsection{Subsection 1}
\chapter{METHODOLOGY} \lipsum{1}
\section{Section 1}
\subsection{Subsection 1}
\chapter{CONCLUSION} \lipsum{1}
\section{Section 1}
\subsection{Subsection 1}
\end{document}
答案1
调整 tocdepth 的正常方法是\setcounter{tocdepth}{...}
。我根据您的 MWE 展示了一些可能性。
% titletocprob.tex SE 597613
\documentclass{report}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{hyperref}
\titleclass{\part}{top} % make part like a chapter
\titleformat{\part}
[display]
{\centering\normalfont\Huge\bfseries}
{\titlerule[2pt]\vspace{3pt}\titlerule[1pt]\vspace{3pt}\MakeUppercase{\partname} \thepart}
{0pt}
{\titlerule[1pt]\vspace{1pc}\huge\MakeUppercase}
%
\titlespacing*{\part}{0pt}{0pt}{20pt}
\makeatletter
\let\titlesec@part\part
\renewcommand{\part}{\@ifstar\part@star\part@nostar}
\def\part@star#1{\NR@gettitle{#1}\titlesec@part*{#1}}
\def\part@nostar{\@ifnextchar[\part@nostar@opt\part@nostar@nopt}
\def\part@nostar@nopt#1{\NR@gettitle{#1}\titlesec@part{#1}}
\def\part@nostar@opt[#1]#2{\NR@gettitle{#2}\titlesec@part[#1]{#2}}
\makeatother
\begin{document}
\part{FIRST PART}\label{part:one}
\section*{Local toc}
\setcounter{tocdepth}{5} % down to subparagraphs
\setcounter{tocdepth}{1} % down to sections
\setcounter{tocdepth}{0} % down to chapters
\startcontents[mytoc]
\printcontents[mytoc]{}{0}{}
\chapter{INTRODUCTION} \lipsum{1}
\section{Section 1}
\subsection{Subsection 1}
\chapter{METHODOLOGY} \lipsum{1}
\section{Section 1}
\subsection{Subsection 1}
\chapter{CONCLUSION} \lipsum{1}
\section{Section 1}
\subsection{Subsection 1}
\end{document}