Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide an entry from Toc in latex

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} 
like image 340
mjsr Avatar asked May 06 '10 23:05

mjsr


People also ask

How do you hide something in LaTeX?

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

How do I hide sections in overleaf?

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.

How do you make a section without numbers in LaTeX?

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


2 Answers

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} 
like image 164
Ivan Andrus Avatar answered Sep 21 '22 13:09

Ivan Andrus


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

like image 20
Daniel Avatar answered Sep 23 '22 13:09

Daniel