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.
- 199
- 1
- 1
- 9
3 Answers
Maybe you can use a KOMA-Script class:
\documentclass[emulatestandardclasses]{scrbook}
\renewcommand\addchaptertocentry[2]{\addtocentrydefault{chapter}{}{#2}}
\usepackage{blindtext}% dummy text
\begin{document}
\tableofcontents
\Blinddocument
\Blinddocument
\end{document}

- 85,675
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:
tocdepthdecides, which levels are shown in the toc (-1 downto 6) fromparttosubparagraph(for standard LaTeX classes)secnumdepthdecides 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}

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}

-
1:This code entirely removes chapters from toc. The OP wants only to remove chapter numbering in toc, if I've well understood. – Bernard Feb 18 '15 at 00:46
-
A solution with titletoc:
\documentclass[11pt, a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{microtype}
\usepackage{titletoc}%
\titlecontents{chapter}[0em]{\lsstyle\smallskip\bfseries}%\vspace{1cm}%
{}%
{\itshape\bfseries}%numberless%
{\hfill\contentspage}[\medskip]%
%
\titlecontents{section}[4.25em]{\smallskip}%
{\contentslabel[\thecontentslabel]{2em}}%numbered
{\hspace*{-1em}}%numberless
{\hfill\contentspage}[\smallskip]%
%
\titlecontents{subsection}[7em]{}%
{\contentslabel[\thecontentslabel]{2.75em}}%numbered
{\hspace*{-1em}}%numberless
{\hfill\contentspage}[\smallskip]
\begin{document}
\tableofcontents
\chapter*{INTRODUCTION}
\addcontentsline{toc}{chapter}{INTRODUCTION}
\chapter{A NICE FIRST CHAPTER}
\section{An Introductory Section}
\newpage
\section{Another Section}
\subsection{A Boring Subsection }
\end{document}

- 271,350
MWE;-) – Feb 18 '15 at 00:23secnumdepthdeals with document content, yet you're referring to ToC-related content. Mmmm, please explain. And are you usingtocloftortitletoc(not both)... they're not really compatible. – Werner Feb 18 '15 at 00:32