6

How can I add a chapter entry to TOC without showing the correspondent page number? my documentclass is report and I am generating my TOC like this:

\phantomsection 
\pdfbookmark{\Contents}{contents}
\tableofcontents

Thank you.

12

You could load the tocloft package and issue the command \cftpagenumbersoff{chapter}. This will suppress the showing of the page numbers of chapter-type entries globally.

To make this change apply to only a single instance of a chapter, you might type

\addtocontents{toc}{\cftpagenumbersoff{chapter}}
\chapter{XYZ}
...
\addtocontents{toc}{\cftpagenumberson{chapter}} % to restore the showing of page numbers
| improve this answer | |
3

You can add text to the table of contents using the command \addtocontents. Internally, LaTeX uses a couple of commands to create these entries. So for example to add a line, matching the rest of the contents style for chapters write

\addtocontents{toc}{\protect\contentsline{chapter}{\protect\numberline{}Title of this chapter}{}}

note you need to protect commands that should not be expanded.

Here I assuming you do not wish to have the chapter number displayed, as per your question on bibliographies. If you do wish to have a chapter number, it is inserted as the first argument to \numberline (one can conviently use \thechapter for that).

If you use hyperref too, then \contentsline takes an extra argument, so either write

\addtocontents{toc}{\protect\contentsline{chapter}{\protect\numberline{}Title of this chapter}{}{}}

or

\addtocontents{toc}{\protect\contentsline{chapter}{\protect\numberline{\thechapter}Title of this chapter}{}{chapter.\thechapter}}

for unnumbered/numbered versions.

| improve this answer | |
  • This does cause ! Argument of \contentsline has an extra }. for me. – Zelphir Kaltstahl Jul 5 '17 at 11:26
  • @Zelphir What is your documentclass/tocstyle? The above works with book. – Andrew Swann Jul 5 '17 at 19:14
  • I figured it out somehow. I am using book and hyperref. I now use: \cftaddtitleline{toc}{chapter}{<name>}{} instead. Not quite sure what was wrong before. – Zelphir Kaltstahl Jul 5 '17 at 20:19
  • @Zelphir book+hyperref defines no such command; I have now added code for this situation. You must be loading some other package. – Andrew Swann Jul 6 '17 at 8:14
  • 1
    I am loading loads of packages for all sorts of things, so you are probably right about that : ) btw. Is there some search engine, where I can input a command and it tells me which packages implement it? Especially for TeX or LaTeX? Using a normal search engine one can find questions about unknown control sequences and this way indirectly figuring it out, but that is not perfect. (I figured out the command comes from tocloft this way.) – Zelphir Kaltstahl Jul 6 '17 at 8:18

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.