[Tex/LaTex] How to hide chapter numbering in table of contents

table of contentstitletoctocloft

I know \setcounter{secnumdepth}{1} lets you set the depth of numberings, but I have to number sections and subsections only, not chapters. Is there a one-liner to do this? I have seen some answers to similar problems, but they seem overly complicated for such a simple task.

Best Answer

The very fancy and sophisticated package etoc by our fellow user jfbu provides the means for this.

By using \etocsetlevel{level name}{level value} it's possible to shift the structure level (e.g. chapter) to some lower level (say, beyond subparagraph) and then restrict the tocdepth counter to some value above.

\etocsetlevel{chapter}{6} and \setcounter{tocdepth}{4} will do the job.

This affects only the representation in the ToC, not in the main part of the document.

An adjustment of spacings within the ToC might be necessary, this can be achieved with the various \cft.... commands from the tocloft package (not used here)

Please note the difference between secnumdepth and tocdepth counters:

  • tocdepth decides, which levels are shown in the toc (-1 downto 6) from part to subparagraph (for standard LaTeX classes)
  • secnumdepth decides which levels get section numbers in the main document.

\documentclass{book}
\usepackage{etoc}       
\setcounter{secnumdepth}{4}% Show down to subsubsection
\begin{document}    

\setcounter{tocdepth}{4} %for main TOC, only show chapter/section
\etocsetlevel{part}{6} % push away the chapters
\etocsetlevel{chapter}{6}  % push away the chapters, beyond toc depth (4 )
\tableofcontents
\chapter{this is chapter heading}    
  \section{this is section heading}
  \subsection{this is subsection heading}
  \subsubsection{this is subsubsection heading}
  \subsubsection{this is another subsubsection heading}
  \chapter{another chapter}
  \section{this is yet another section} 
\end{document}

enter image description here

Edit

If only the numbers of the chapters should be removed (however, not for section 1.1 etc. ), one trick is to patch the \@chapter command:

\documentclass{book}
\usepackage{tocloft}
\setcounter{secnumdepth}{4}% Show down to subsubsection

\setlength{\cftchapindent}{-20pt}% Just some value...

\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@chapter}{\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}}{%
                      \addcontentsline{toc}{chapter}{\protect\numberline{}#1}}{\typeout{Success}}{\typeout{Failed!}}
\makeatother

\begin{document}    

\tableofcontents

%\renewcommand{\thechapter}{\arabic{chapter}}
\chapter{First chapter}
  \section{First section}
  \subsection{First subsection}
  \subsubsection{Even more in the basement}
  \chapter{Another chapter}
  \section{this is yet another section} 
\end{document} 

enter image description here

Related Question