Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
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 '11 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. –  Torbjørn T. Oct 14 '11 at 7:30
add comment

4 Answers

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}
share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
tocbibind produces right page number in toc, but it links Index to the previous chapter. –  Anton Petrunin Feb 7 '13 at 19:04
1  
@AntonPetrunin: What happens when you place a \phantomsection before the index? –  Stephen Feb 7 '13 at 20:06
    
yes it works, thank you. –  Anton Petrunin Feb 10 '13 at 4:14
add comment

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}
share|improve this answer
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. –  barbara beeton Nov 21 '13 at 21:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.