TOC 隐藏编号的子部分,但仅在一个部分下

TOC 隐藏编号的子部分,但仅在一个部分下

我有一份像这样的文件

\documentclass{book}

\begin{document}
\tableofcontents


\chapter{Intro}
\chapter{Body}
\section{A section}
\subsection{A sub-section to number and include in TOC}
\subsection{Another sub-section to number and include in TOC}
\section{Another section}
\subsection{Number but do not include in the TOC}
\subsection{Another to number but do not include in the TOC}
\section{More}
\subsection{A sub-section to number and include in TOC}

\end{document}

我想对目录中某一特定部分下的子部分进行编号,但隐藏这些子部分。使用\subsection*{}会隐藏这些子部分,但也会导致它们在文档中不被编号。

这样做的原因是某个特定部分下有太多小节。这会使目录太长,而且其实没有必要。

答案1

您可以添加\setcounter{tocdepth}{<level>}部分命令来本地更改目录的深度。

\documentclass{book}

\begin{document}
\tableofcontents


\chapter{Intro}
\chapter{Body}
\section{A section\setcounter{tocdepth}{1}}

\subsection{A sub-section to number and include in TOC}
\subsection{Another sub-section to number and include in TOC}
\section{Another section\setcounter{tocdepth}{2}}

\subsection{Number but do not include in the TOC}
\subsection{Another to number but do not include in the TOC}
\section{More}
\subsection{A sub-section to number and include in TOC}

\end{document}

在此处输入图片描述

相关内容