【问题标题】:hide an entry from Toc in latex在乳胶中隐藏 Toc 的条目
【发布时间】:2012-12-19 15:03:49
【问题描述】:

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

\documentclass{article}

\begin{document}
\tableofcontents
\section{uno}
\section{dos}
\section*{hide}
\section{tres}
\end{document}

【问题讨论】:

  • 最好也省略右边的页码..我只需要SectionName........SectionNumber SectionName2..... ......SectionNumber2 ...等

标签: latex tableofcontents


【解决方案1】:

我想你正在寻找

\section*{hide}
\addtocounter{section}{1}

或者把它变成一个命令:

\newcommand{\toclesssection}[1]{\section*{#1}\addtocounter{section}{1}}

编辑:

好的,我想我明白现在想要什么(这比我给出的答案更有意义)。这是一个命令,您可以使用它来禁止向 TOC 添加节、小节等。这个想法是暂时禁用\addcontentsline

\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
...
\tocless\section{hide}
\tocless\subsection{subhide}

【讨论】:

  • OP 说“不丢失正文中的节号”
  • 问题依然存在并出现其他不一致。在 Toc 部分 tres 的编号为 3,在 body 中的编号为 4。
  • 嗯,我不明白命令集中的逻辑,你能用英语给我提示吗?...我试图使用 tocless 命令但不起作用。
  • 一个小改进:要引用文档中其他地方的隐藏部分,您需要在组内添加\label。例如,\newcommand{\toclesslab}[3]{\bgroup\let\addcontentsline=\nocontentsline#1{#2\label{#3}}\egroup} 将修复它。用法:\toclesslab\section{Motivation}{s:motivation} 将阻止该部分出现 TOC,但您仍然可以使用 \ref{s:motivation} 或类似名称引用它。
  • 请参阅 stackoverflow.com/a/3805470/431528 以获得不会导致格式问题的答案。
【解决方案2】:

只是想对 Ivans 的精彩提示表示感谢! (我只是在谷歌上为我的自定义(子)附录{}命令寻找类似的东西:

\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}}

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

【讨论】:

    【解决方案3】:

    刚刚从a similar question. 来到这里 上面的答案不太有效,因为它给出了一些格式问题,但similar solution 似乎可以解决问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      相关资源
      最近更新 更多