在乳胶中隐藏Toc的条目

mjs*_*jsr 37 latex tableofcontents

我想知道如何隐藏目录中的一个部分,但不会丢失文档正文中的部分编号.例如,在这个tex文件中,我丢失了数字hide,并且所有序列都被损坏了:

\documentclass{article}

\begin{document}
\tableofcontents
\section{uno}
\section{dos}
\section*{hide}
\section{tres}
\end{document}
Run Code Online (Sandbox Code Playgroud)

Iva*_*rus 56

我想你在找

\section*{hide}
\addtocounter{section}{1}
Run Code Online (Sandbox Code Playgroud)

或者把它变成一个命令:

\newcommand{\toclesssection}[1]{\section*{#1}\addtocounter{section}{1}}
Run Code Online (Sandbox Code Playgroud)

编辑:

好吧,我想我现在明白了什么(而且我给出的答案更有意义).这是一个命令,您可以使用该命令来禁止向TOC添加节,子节等.想法是暂时禁用\addcontentsline.

\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
...
\tocless\section{hide}
\tocless\subsection{subhide}
Run Code Online (Sandbox Code Playgroud)

  • 一个小的改进:要引用文档中其他地方的隐藏部分,您需要在组内添加`\ label`.例如,`\newcommand {\ toclesslab} [3] {\ bgroup\let\addcontentsline = \nocontentsline#1 {#2\label {#3}}\egroup}`将修复它.用法:`\ toclesslab\section {Motivation} {s:motivation}`将使该部分不会出现在TOC中,但你仍然可以用`\ ref {s:motivation}'或类似的方式引用它. (4认同)
  • 有关不会导致格式问题的答案,请参阅http://stackoverflow.com/a/3805470/431528。 (2认同)

小智 5

只是想对伊万的提示表示感谢!(我只是在为我的自定义 (Sub)Appendix{} 命令搜索类似的东西:

\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

\newcommand{\Appendix}[1]{
  \refstepcounter{section}
  \section*{Appendix \thesection:\hspace*{1.5ex} #1}
  \addcontentsline{toc}{section}{Appendix \thesection}
}
\newcommand{\SubAppendix}[1]{\tocless\subsection{#1}}
Run Code Online (Sandbox Code Playgroud)

也许这对其他人也有用......)