3

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.

8
  • 1
    The magic keyword is MWE ;-)
    – user31729
    Feb 18, 2015 at 0:23
  • You still want the chapters numbered, but just not in the ToC? secnumdepth deals with document content, yet you're referring to ToC-related content. Mmmm, please explain. And are you using tocloft or titletoc (not both)... they're not really compatible.
    – Werner
    Feb 18, 2015 at 0:32
  • It's the same. In the requirements for my document there are no specifications regarding the numbering of the content. I thought of it as a workaround to hide them from the TOC.
    – Federico
    Feb 18, 2015 at 0:42
  • @Federico: Could you make your question less ambiguous so it's helpful to other people as well? Give an example of the input you would supply, what things will/should look like in your document and what they should look like in the ToC...
    – Werner
    Feb 18, 2015 at 0:54
  • @Federico: Did you want to hide the numbering only or the the complete chapter entries. In the first case, please unaccept my answer, it does not address your request, I've misinterpreted your question then
    – user31729
    Feb 18, 2015 at 0:56

3 Answers 3

2

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

2
  • 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, 2015 at 0:46
  • @Bernard: Damn, your right... I misinterpreted ;-)
    – user31729
    Feb 18, 2015 at 0:51
3

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}

enter image description here

2

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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .