
目次からサブセクションを削除する必要があります。これを使用して問題なくその部分を削除できました。リンク。 ありがとう!
\ref{"label from my subsection"}
しかし、ToC から削除したばかりの選択したサブセクションには使用できません。リンクは引き続き可能ですが、サブセクションの上のセクションへの参照のみ取得されます。
例: (私のサブセクションは目次に表示されません)
\section{Hello World!}
\label{sec:hello_world}
\subsection{Goodbye}
\label{sec:goodbye}
\ref{sec:goodbye}
--- Latex は以下の結果を返します ---
1. こんにちは世界!
1.1. さようなら
1
答え1
\subsection
目次からすべての を削除したい場合は、文書の序文に次のものを追加してください。
\setcounter{tocdepth}{1}
これにより、ToC 内のエントリの最大深度が 1 (または\section
) に設定されます。
\subsections
選択したものを ToC に挿入する/しないだけの場合は、別の手法を使用する必要があります。以下は\stoptocentries
、 と を定義します\starttocentries
。前者は、 を無効にすることで ToC へのコンテンツの挿入を無効にします\addcontentsline
。後者は機能を復元します。
\documentclass{article}
\let\oldaddcontentsline\addcontentsline
\newcommand{\stoptocentries}{\renewcommand{\addcontentsline}[3]{}}
\newcommand{\starttocentries}{\let\addcontentsline\oldaddcontentsline}
\begin{document}
\tableofcontents
\section{A section}
\stoptocentries% Stop adding content to the ToC
\subsection{A subsection}
\starttocentries% Resume adding content to the ToC
\subsection{Another subsection}
\end{document}
もちろん、 の使用法は、\stoptocentries
を使用する他のセクション単位にも適用されます\addcontentsline
。
答え2
パッケージを使えばすぐに実行できますエトック。
コード:
\documentclass{article}
\usepackage{etoc}
\begin{document}
\tableofcontents
\section{First Section}
Hello
\subsection{A}
\subsection{B}
\section{Second Section}
\etocsettocdepth.toc {section}
\subsection {EXCLUDE ME}\label{ssec:excluded}
\etocsettocdepth.toc {subsection}
\subsection {D}
Too bad we have excluded subsection \ref{ssec:excluded} from the TOC!
\end{document}
答え3
上記の回答は質問に完全に答えていると思いますが、LaTeXのウェブサイトで別の方法を見つけた。
toc 内のすべてのサブセクションを非表示にする場合は、カウンター tocdepth を 1 に設定する必要があります。
\setcounter{tocdepth}{1}
ただし、これを特定の (サブ) セクションにのみ適用したい場合は、ドキュメント内の tocdepth を変更できます。
\documentclass[a4paper,10pt]{book}
\begin{document}
\tableofcontents
\chapter{One}
\section{One}
\subsection{One}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\subsection{Two}
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\subsection{Three}
\end{document}