9

I have a large document with an index compiled through makeindex, and is included in my source .tex as follows:

\cleardoublepage
\phantomsection 
\addcontentsline{toc}{chapter}{Index}
\printindex

However, the \addcontentsline does not correctly add the Index to either the Table of Contents, or the list of bookmarks in the resulting PDF.

Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . 330

One solution is to write a new command, \immediateaddcontentsline, and this adds the Index to both the TOC and the list of Bookmarks. The Bookmark link works correctly. But in the TOC, the page number is now listed with roman numerals as "xvi" rather than "349".

Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . 330

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi

"xvi" is the current page, so it looks like something is mighty confused. It is probably related to the immediate-ness of the new TOC command.

Is it even possible to have an Index listed the Table of Contents? Or must I use a different index maker?

2
  • 1
    Which document class are you using? The KOMA classes, for example, provide an option to include the index in the table of contents (and the Memoir classes might have a similar option). As we cannot guess what you did with your \immediateaddcontentsline command, please add a minimal working example (MWE) that illustrates your problem.
    – domwass
    Oct 14, 2011 at 7:30
  • 1
    Could the tocbibind package be of help? Edit: If you're using KOMA rather use domwass' suggestion, tocbibind is made to work with the standard classes. Oct 14, 2011 at 7:30

4 Answers 4

16

Instead of tinkering with \addcontentsline, simply load my idxlayout package with the totoc option. (idxlayout is compatible with the standard classes, the KOMA-Script classes, and memoir.)

\documentclass{report}

\usepackage{makeidx}
\makeindex

\usepackage[totoc]{idxlayout}

\usepackage{hyperref}

\begin{document}

\tableofcontents

\chapter{foo}

Some text.\index{Text}

\printindex

\end{document}
6

assuming that \printindex triggers \chapter* and chapters always start on right-hand pages, try inserting \cleardoublepage and then the \addcontentsline. if a chapter can start on either a right-hand or a left-hand page, \clearpage should suffice.

2
  • What should be the sequence of commands: \printindex\cleardoublepage\addcontentsline?
    – Sigur
    Jan 12, 2016 at 22:21
  • 2
    @Sigur -- no. \cleardoublepage \addcontentsline{toc}{...} \printindex. (ams document classes include even starred headings in the toc; easiest way to conform to house style.) Jan 12, 2016 at 22:30
2

As alternative there is also the tocbibind package to include the table of contents, bibliography and index in the table of contents. If you only want to include the index, use

\usepackage[nottoc,notbib]{tocbibind}

and place a \phantomsection before the index, so that the hyperlink does not aim at some content before the index.

2
  • tocbibind produces right page number in toc, but it links Index to the previous chapter. Feb 7, 2013 at 19:04
  • 1
    @AntonPetrunin: What happens when you place a \phantomsection before the index?
    – Stephen
    Feb 7, 2013 at 20:06
1

Reversing the order of the lines might do the trick, e.g.,

\printindex
\addcontentsline{toc}{chapter}{Index}

At least, it did when I had the analogous problem with a bibtex bibliography,

\bibliography{references}
\addcontentsline{toc}{section}{References}
1
  • 2
    if the index is more than one page long, this will still get the wrong page number. the \addcontentsline needs to be triggered before the end of the first page of index entries. since you don't want to edit the .ind file, this is best done by using a document class that doesn't omit \chapter* from the toc, by inserting \clear[double]page before the \addcontentsline, by patching the \printindex command, or by using a package like tocbibind as suggested in a previous answer. Nov 21, 2013 at 21:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .