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.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityHow 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.
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
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.
! Argument of \contentsline has an extra }.
for me.
– Zelphir Kaltstahl
Jul 5 '17 at 11:26
book
.
– Andrew Swann
Jul 5 '17 at 19:14
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
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
tocloft
this way.)
– Zelphir Kaltstahl
Jul 6 '17 at 8:18