13

In my LaTeX document, I want to add some extra lines in the Table of Contents to show the general topic of the next section of chapters. The syntax I'm using right now, outlined in a quick example:

\tableofcontents
\chapter{Chapter A}
some text
\chapter{Chapter B}
some text
\renewcommand{\thepart}{} %Removes the counting in roman numerals before the part name
\addcontentsline{toc}{part}{And now for something completely different} %Adds it to the table of contents without it showing up in the document.
\chapter{Chapter C}
some text
\chapter{Chapter D}
some text

However, I want to remove the page number that appears besides the title of 'And now for something completely different' in the Table of Contents. Is there an (easy, preferably without creating your own packages) way to do so?

22

instead of \addcontentsline, use the more general \addtocontents which allows you to be specific about all parts of a contents line:

\addtocontents{toc}{%
  \protect\contentsline{part}{And now for something completely different}{}}

the final empty group {} takes the place of what is usually filled with the page number.

  • 7
    This doesn't work with hyperref package "Argument of \contentsline has an extra }. \contentsline" – Masood_mj Jun 6 '16 at 21:26
  • 1
    @Masood_mj seems to stem from hyperref package, which overrides that command, according to other posts I read on here. – Zelphir Kaltstahl Jul 5 '17 at 12:08
  • 1
    To fix the Argument of \contentsline has an extra}. \contentsline due to hyper ref, see this post – Frenzy Li Jan 16 at 15:12

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.