hide an entry from Toc in latex

后端 未结 3 1205
梦毁少年i
梦毁少年i 2020-12-13 17:38

I would like to know how I can hide a section from the table of contents but without loosing the section number in the body of the document. For example, in this tex

相关标签:
3条回答
  • 2020-12-13 18:00

    I think you are looking for

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

    or make it into a command:

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

    EDIT:

    Okay, I think I understand what is wanted now (and it makes more sense then the answer I gave). Here is a command that you can use to suppress adding a section, subsection, etc. to the TOC. The idea is to temporarily disable \addcontentsline.

    \newcommand{\nocontentsline}[3]{}
    \newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
    ...
    \tocless\section{hide}
    \tocless\subsection{subhide}
    
    0 讨论(0)
  • 2020-12-13 18:03

    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...)

    0 讨论(0)
  • 2020-12-13 18:10

    have just come here from a similar question. The answer above didn't quite work as it gave some formatting issues, but a similar solution seemed to do the trick

    0 讨论(0)
提交回复
热议问题