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 file I loose the number for hide
, and all the sequences are damaged:
\documentclass{article} \begin{document} \tableofcontents \section{uno} \section{dos} \section*{hide} \section{tres} \end{document}
For example, \hide{this is some hidden text} will allocate space in the pdf for that string, but will never actually print it -- it will be just white. Or alternatively, it should also work with \hide{\includegraphics[width=3in]{image. png}} .
If you're working on large documents, and want to hide some of your code to make it easier to navigate, you can! Click the small triangle next to the line number of the chapter, part, section, or subsection label command to fold or unfold the code.
If you'd prefer your sections, subsection, and so forth to be displayed without numbers on the left side of the title, you simply add a * symbol to the command. (Note that section headings created this way will not be listed in the table of contents \tableofcontents.)
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}
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...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With