45

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

\documentclass{article}

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

3 回答 3

69

我想你正在寻找

\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}
于 2010-05-07T02:05:20.800 回答
5

Just wanted to say thanks for Ivans great hint! (I was just googling for something similar for my customized (Sub)Appendix{} commands:

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

Maybe this is useful for someone else, too...)

于 2010-06-24T12:14:25.483 回答
3

刚刚从一个类似的问题来到这里。上面的答案不太有效,因为它给出了一些格式问题,但类似的解决方案似乎可以解决问题

于 2010-09-27T21:10:44.977 回答