Using \setcounter{tocdepth}{0} displays just the chapter's title in the table of contents. In the last chapter, there's a subsection. I want to use \setcounter{tocdepth}{0}! Therefore no subsection should be displayed in the table of content. However, using the option 0, a problem shows up. The subsections are not displayed in the table of contents, but there's a gap between the last chapter and the references in the end. It seems like the option 0 just doesn't print the subsection in the contents, leaving some space between the last chapter and the references chapter. I added a picture, as well as the used template (not the complete, it's too long). If I use \setcounter{tocdepth}{1} there is no gap, and everything looks fine! But I do not want to have the sections in the table of content

Here is a test code, but without the thesis.cls it won't compile.

\usepackage{graphicx}   % if you want to include graphics files
%\titlepage             % Print titlepage   
\newpage               % blank page
%\copyrightpage        % optional         
\tableofcontents       % required 
%\listoftables          % required if there are tables
%\listoffigures         % required if there are figures

some text
more text

table of content with gap

Some lines from the thesis.cls file.

%                            SECTION HEADINGS

\setcounter{secnumdepth}{3}    % Number subsubsections in the chapters
\setcounter{tocdepth}{0}       % Put subsubsections in the table of contents

% Print "CHAPTER" if chap option is specified:

\def\specialhead#1{%   GENERAL HEADING WITHOUT A NUMBER (for abstract, etc.)
     \chapter*{\centering #1 \@mkboth{#1}{#1}}}

\def\@chapter[#1]#2{\ifnum\c@firstchapter=0    % start of rpi added stuff
                    \pagestyle{myheadings}      % end of rpi added stuff
                    \ifnum \c@secnumdepth >\m@ne
%                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
%                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
  {\parindent \z@ \raggedright \centering \normalfont \chaptersize
    \ifnum \c@secnumdepth >\m@ne
         \bfseries \@chapapp{} \thechapter    % print "Chapter" and number
         \vskip -3pt           %\par\nobreak (original)
         \bfseries \thechapter. 
    \bfseries #1\par\nobreak
    \vskip 15\p@

\def\@makeschapterhead#1{%    heading for chapter* command (no numbering)
  {\parindent \z@ \raggedright \centering
    \normalfont  \chaptersize 
    \bfseries  #1\par\nobreak
    \vskip 15\p@

\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {3.5ex \@plus 1ex \@minus .2ex}%
                                   {.5ex \@plus .3ex}%{1.4ex \@plus.2ex}%
                                     {3.25ex\@plus 1ex \@minus .2ex}%
                                     {.3ex \@plus .2ex}%{1.2ex \@plus .2ex}%
                                     {3.25ex\@plus 1ex \@minus .2ex}%
                                     {.2ex \@plus .1ex}%{1ex \@plus .2ex}%
% \paragraph and \subparagraph headings unchanged from report.cls.

    \vskip -1em \begin{singlespace}      % singlespacing

\renewcommand*\l@chapter{\pagebreak[3]\vskip 10pt plus 1pt minus 1pt
\renewcommand*\l@section{\vskip 6pt plus 1pt minus 1pt
\renewcommand*\l@subsection{\ifnum\c@tocdepth>1\vskip 4pt minus 1pt \fi
\renewcommand*\l@subsubsection{\ifnum\c@tocdepth>2 \vskip 3pt minus 1pt \fi

% The following removed because it's not consistent with entries from longtable
%% modify the definition below (taken from latex.ltx) to include 
%% "Table" and "Figure" in entries for lot and lof: 
%\long\def\@caption#1[#2]#3{%\baselineskip 14.5 pt
%  \addcontentsline{\csname ext@#1\endcsname}{#1}%
%  {\protect\numberline{\csname fnum@#1\endcsname}{\ignorespaces #2}}%
%  \begingroup
%    \@parboxrestore
%    \normalsize
%    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
%  \endgroup}

    \addcontentsline{toc}{chapter}{\listfigurename}  % add lof to toc
    \chapter*{\centering\listfigurename  % center it
    \vskip -1em \begin{singlespace}  % singlespacing

    \addcontentsline{toc}{chapter}{\listtablename}  % add lot to toc
    \chapter*{\centering\listtablename  % center it
        \vskip -1em \begin{singlespace}  % singlespacing

%remove following at same time as remove code to put "Figure" in LOF
%\renewcommand*\l@figure{\vskip 10pt plus 1pt minus 1pt
%                       \@dottedtocline{1}{0em}{5.8em}}

\renewcommand*\l@figure{\vskip 10pt plus 1pt minus 1pt


% RPI def: for use in making an unnumbered bibliography with hanging indents

% report definition modified for no automatic heading and use ragged right

       {\@latex@warning{Empty `thebibliography' environment}}%
  • 1
    Please add a minimal working example (MWE) that illustrates your problem. Commented Jun 8, 2012 at 16:44
  • @ Martin Schröder: Sorry, added the picture.
    – m. th
    Commented Jun 8, 2012 at 16:46
  • 3
    You've already included hundreds of lines of code - please make that an MWE. Commented Jun 8, 2012 at 16:47

2 Answers 2


If you wish to selectively include/exclude things in the ToC that differ from your "default" choice for tocdepth, then you need to insert these variations into the ToC file itself. The reason for this is because the ToC is processed before (and therefore separate from) the sectional units. So, by the time you're possibly making momentary changes to tocdepth, the ToC has already been typeset.

Here's a small example of how you could incorporate an inclusion of a \section even though tocdepth has been set to 0 (only allowing \chapters to be included):

enter image description here

\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\setcounter{tocdepth}{0}% Allow only \chapter in ToC
\section{A section}
\chapter{Another chapter}
\chapter{Yet another chapter}
\addtocontents{toc}{\setcounter{tocdepth}{1}}% Allow \section in ToC
\section{Another section}
\addtocontents{toc}{\setcounter{tocdepth}{0}}% Allow only \chapter in ToC

You also need to update your \l@section macro to only insert a vertical space when tocdepth allows it. Here's update version:

% Original \l@section:
%\renewcommand*\l@section{\vskip 6pt plus 1pt minus 1pt
%                         \@dottedtocline{1}{1.5em}{2.3em}}
% Modified \l@section:
\renewcommand*\l@section{\ifnum\c@tocdepth>\z@\vskip 6pt plus 1pt minus 1pt \fi
  • adding \addtocontents{toc}{\setcounter{tocdepth}{0}} after the section, which should not be in the table of content does not solve my probelm. I still get this gap between "Application" and "References"
    – m. th
    Commented Jun 8, 2012 at 17:08
  • 1
    @math: You need to have a modified version of \l@section which conditionally inserts \vskip. Yours currently inserts it regardless of whether tocdepth is 0 or not. That's what causing the strange spacing in your ToC. I've included an updated version at the end of my answer.
    – Werner
    Commented Jun 8, 2012 at 17:32
  • @ Wener: Now everything is fine! Thank you so much!
    – m. th
    Commented Jun 8, 2012 at 17:43
  • 3
    Quick comment in case others have the same issue with this that I did: if you are using certain other packages, you may have to \protect the \setcounter as per this answer. Commented Apr 5, 2014 at 13:03

before the chapter for which you want to include the sections in the toc, add the line


you can later reset it to include just the chapters with

  • @ barbara beeton: Thank you for your answer. I tried to use \addtocontents{toc}{\setcounter{tocdepth}{0}} in the section. The gap is still there in the table of content. Maybe my question was not that clear. I edited it.
    – m. th
    Commented Jun 8, 2012 at 17:32
  • @math -- thanks for editing the question; i interpreted it differently when i first read it. i tried to replicate your problem with the report class (since i don't have thesis), and the problem doesn't occur there. so werner's interpretation and solution are applicable. Commented Jun 8, 2012 at 17:48
  • @ barbara beeton: mea culpa for the unclarity. Nevertheless, thank you for help!
    – m. th
    Commented Jun 8, 2012 at 18:44
  • It seems that using this will render the \listoffigures blank. Any idea on this? I am setting it to 0 just before including some javadoc API pdf, then resetting it back to 5.
    – Timotei
    Commented Jul 3, 2013 at 12:26
  • @Timotei -- sorry, i have no idea why something added explicitly to the toc would affect the \listoffigures. are you saying you added \addtocontents{lof}{...}? is there anything in your .lof file? i'm not sure how tocdepth interacts with lists of figures or tables. Commented Jul 3, 2013 at 18:11

You must log in to answer this question.

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