2

I am trying to exclude an entry from my table of contents, but I want to keep the numbering, so e.g. \chapter*{} won't work for me.

I googled around a bit, but all solutions seem to be equivalent to \chapter*{}.

The reason for my problem is that I'm adding a "list of appendices" below the TOC, so I need numbering for referencing, but it looks kind of dumb to have the list in the TOC as well.

3

Here's another proposition with tocdepth counter manipulation, however, this won't prevent the addition of the relevant chapter in the bookmarks.

\documentclass{book}


\newcounter{oldtocdepth}

\newcommand{\hidefromtoc}{%
  \setcounter{oldtocdepth}{\value{tocdepth}}%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-10}}%
}

\newcommand{\unhidefromtoc}{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{\value{oldtocdepth}}}%
}
\usepackage{hyperref}
\usepackage{bookmark}


\begin{document}
\tableofcontents
\chapter{Foo chapter}


\hidefromtoc
\chapter{List of Appendices}
\unhidefromtoc
\chapter{Other foo chapter}

\end{document}

The screen shot shows the unpleasant feature of the request: If there's another chapter afterwards, there's a gap in counting in the ToC, however, since it is the appendix, there are no further chapters after the appendix, most likely.

enter image description here

  • The unpleasant feature doesn't matter, the appendix is the last part of my document. – Anders Olsen Mar 17 '17 at 16:51
  • Your solution works, but in order to make it work as intended, I have to throw in the \hidefromtoc before the chapter previous from the one I want to hide, like this: \chapter{unhidden chapter} \hidefromtoc \chapter{last unhidden chapter} \appendix \chapter{first hidden chapter} .. \chapter{last hidden chapter} \unhidefromtoc \end{document} Maybe this is because of the appendix environment, I don't know. Either way, your solution works when I do that, so thanks a lot! – Anders Olsen Mar 17 '17 at 16:56
  • @AndersOlsen: Please consider to accept the solution then. – user31729 Mar 17 '17 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.