51

I'm having a very weird problem. The following example should illustrate it quite right.

\documentclass[a4paper,12pt]{memoir}    
\begin{document}
\frontmatter
  \tableofcontents
  \clearpage
\mainmatter
  \chapter{Chapter 1}
\end{document}

I've compiled it with xelatex but on the table of contents page, it is referencing the table of contents page as Contents, which is the header of that page as well. It does make sense to me to a certain extend. But I'd still like to know how to get rid of the self-reference.

Caramdir
  • 89,023
  • 26
  • 255
  • 291
angerman
  • 1,225

5 Answers5

37

\KeepFromToc helps in suppressing TOC entries for such \listof commands:

\begin{KeepFromToc}
  \tableofcontents
\end{KeepFromToc}
Stefan Kottwitz
  • 231,401
35

Thanks to Martin Scharrer, I paid a more attention to the memoir class as the source of the issue.

A closer examination of the memoir README reveals \tableofcontents* as a solution. Seems logical, everything I want to hide gets the star.

Caramdir
  • 89,023
  • 26
  • 255
  • 291
angerman
  • 1,225
19

I suggest you, if using the tocbibind package:

\usepackage[nottoc]{tocbibind}
Werner
  • 603,163
  • Did you actually test this? – daleif Mar 08 '16 at 16:14
  • 1
    Worked for me, using a class based off of report. In my case, tocbibind (which I was using to include my figure and table lists in the TOC) was what caused the TOC to appear in the TOC in the first place. – golvok Aug 10 '19 at 00:57
  • 1
    Works for me on Overleaf with document class article. – Morten Engelsmann Aug 04 '20 at 15:32
  • Worked for me, too. I am using the scrbook class. – Sven Büchel Aug 19 '21 at 09:13
  • This worked for me using book class. Issue was I had used \usepackage{tocbibind} to get the bibliography to appear in the table of contents, without realizing until much later that it made "contents" appear there too, until adding [nottoc]. – WillG Sep 11 '23 at 22:20
16

I had a similar problem, but with the article class. Neither of the solutions above work for this class, so after much searching I used the advice of Martin above and searched the article class and found that I can simply not use \tableofcontents, and instead use:

\makeatletter
\@starttoc{toc}
\makeatother

This doesn't create a section for the table of contents, so the problem goes away.

Thought I would post this here in case anyone else has a similar problem.

diabonas
  • 25,784
Ashley
  • 161
  • 1
  • 2
7

The following works for supressing the self-referencing TOC entry, and is not specific to memoir (I'm using scrbook):

\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\tableofcontents
\addtocontents{toc}{\protect\setcounter{tocdepth}{3}}

You can of course replace the 3 with whatever tocdepth you prefer to have.

Mark
  • 1,855