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.

Friends, I'm stuck with a funny error: when I add multiple indices in my table of contents, all page number references mess up. It's probably something easy to solve, but I can't figure out what it is.

Consider this non-so-minimum example (sorry, I had no choice):

\documentclass[twoside]{book}

\usepackage{idxlayout}

\usepackage[useindex]{splitidx}

\makeindex

\newindex[Index A]{ia}
\newindex[Index B]{ib}
\newindex[Index C]{ic}
\newindex[Index D]{id}

\newcommand*\indexall[1]{%
\sindex[ia]{#1}%
\sindex[ia]{#1#1}%
\sindex[ia]{#1#1#1}%
\sindex[ia]{#1#1#1#1}%
\sindex[ia]{#1#1#1#1#1}%
\sindex[ia]{#1#1#1#1#1#1}%
\sindex[ia]{#1#1#1#1#1#1#1}%
\sindex[ia]{#1#1#1#1#1#1#1#1}%
\sindex[ib]{#1}%
\sindex[ib]{#1#1}%
\sindex[ib]{#1#1#1}%
\sindex[ib]{#1#1#1#1}%
\sindex[ib]{#1#1#1#1#1}%
\sindex[ib]{#1#1#1#1#1#1}%
\sindex[ib]{#1#1#1#1#1#1#1}%
\sindex[ib]{#1#1#1#1#1#1#1#1}%
\sindex[ic]{#1}%
\sindex[ic]{#1#1}%
\sindex[ic]{#1#1#1}%
\sindex[ic]{#1#1#1#1}%
\sindex[ic]{#1#1#1#1#1}%
\sindex[ic]{#1#1#1#1#1#1}%
\sindex[ic]{#1#1#1#1#1#1#1}%
\sindex[ic]{#1#1#1#1#1#1#1#1}%
\sindex[id]{#1}%
\sindex[id]{#1#1}%
\sindex[id]{#1#1#1}%
\sindex[id]{#1#1#1#1}%
\sindex[id]{#1#1#1#1#1}%
\sindex[id]{#1#1#1#1#1#1}%
\sindex[id]{#1#1#1#1#1#1#1}%
\sindex[id]{#1#1#1#1#1#1#1#1}}%
\begin{document}

\tableofcontents

\chapter{My text}

Hello world.

\indexall{A}
\indexall{B}
\indexall{C}
\indexall{D}
\indexall{E}
\indexall{F}
\indexall{G}
\indexall{H}
\indexall{I}
\indexall{J}
\indexall{K}
\indexall{L}
\indexall{M}
\indexall{N}
\indexall{O}
\indexall{P}
\indexall{Q}
\indexall{R}
\indexall{S}
\indexall{T}
\indexall{U}
\indexall{V}
\indexall{W}
\indexall{X}
\indexall{Y}
\indexall{Z}

\addcontentsline{toc}{chapter}{Index A}
\printindex[ia]
\addcontentsline{toc}{chapter}{Index B}
\printindex[ib]
\addcontentsline{toc}{chapter}{Index C}
\printindex[ic]
\addcontentsline{toc}{chapter}{Index D}
\printindex[id]

\end{document}

(every time you run this code, a kitten dies)

The generated table of contents is as follows:

My table of contents

At least, this time I got odd numbers in my ToC. The previous attempt raised even numbers (!).

The correct reference should be:

Index A -  5
Index B -  9
Index C - 13
Index D - 17

If I put \cleardoublepage before the indices, I get this ToC (the first index is fixed):

Table 2

I really can't understand what's going on. I can't even establish a pattern.

Does anyone have a suggestion?

(no animals were harmed in the making of this question)

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Have you tried issuing a \cleardoublepage command before each \addcontentsline command?

share|improve this answer
    
Thanks, it works! TBH, I thought that would be unnecessary, since my indices were displayed in the correct pages. But I was mistaken! Cheers! –  Paulo Cereda Aug 26 '11 at 20:30
    
I think the problem lies with the way that the TeX engine determines page numbers; judging from some of the discussions I've followed in comp.text.tex on just this subject, TeX's algorithm is unfortunately anything but fail-safe. Hence it's sometimes necessary to add a few \clearpage and/or \cleardoublepage commands here and there to help TeX out. –  Mico Aug 26 '11 at 20:39
2  
to me, this is one of the unfortunate side-effects of omitting unnumbered (starred) chapters, sections, etc., from the toc, a practice which i think is misguided. i would find it preferable to include the mechanism for including this information in the toc, but omitting it by a documentclass option. (personal opinion, not necessarily the opinion of the organization that pays me, although their document classes do include unnumbered segments in the toc, resulting in occasional inquiries about how to suppress them.) include or exclude is often a "house style" matter. –  barbara beeton Aug 29 '11 at 18:41

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.