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 two indexes: the Main Index and Name Index. The PDF books are visually correct:

enter image description here

Note that the Name Index starts on Page 6, and the Z entry for the Name Index is on Page 7.

However, up clicking on the Z in the Name Index (which appears on Page 7) I am taken to the Z for the Main Index (Page 6).

This code is adapted form Applying \lowercase to index entries.

Code:

\documentclass{article}
\usepackage{imakeidx}
\usepackage{hyperref}

\newcommand*\lettergroup[1]{%
    \clearpage%
    \section*{#1}%
    \pdfbookmark[0]{#1}{#1}% 
    \nopagebreak%
}

% http://tex.stackexchange.com/questions/51688/applying-lowercase-to-index-entries
\newcommand*{\AddIndexEntry}[3][]{%
  % #1 = indexed term, #2 = word to index this under
  \par\noindent
  \lowercase{\def\temp{#3}}%
  Indexing: #3%
  \if!#1!
    \expandafter\index\expandafter{\temp!#2}%
  \else
    \expandafter\indexopt\expandafter{\temp!#2}{#1}
  \fi
}
\newcommand{\indexopt}[2]{\index[#2]{#1}}

\makeindex[title={Main Index},columns=1,program=texindy]
\makeindex[title={Name Index},columns=1,program=texindy,name=Name]

\begin{document}

\AddIndexEntry{aardvark}{aardvark}
\AddIndexEntry{Saved by Zero}{Saved}
\AddIndexEntry{Saved by Zero}{Zero}
\AddIndexEntry[Name]{zero}{zero}

\clearpage
\addcontentsline{toc}{}{Main Index}
\printindex

\clearpage
\addcontentsline{toc}{}{Name Index}
\printindex[Name]
\end{document}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Rather than doing manual bookmark placement, I believe it's better to let hyperref work:

\documentclass{article}
\usepackage{imakeidx}
\usepackage{hyperref}
\usepackage{bookmark}

\newcommand*\lettergroup[1]{\subsection{#1}}

% http://tex.stackexchange.com/questions/51688/applying-lowercase-to-index-entries
\newcommand*{\AddIndexEntry}[3][]{%
  % #1 = indexed term, #2 = word to index this under
  \par\noindent
  \lowercase{\def\temp{#3}}%
  Indexing: #3%
  \if!#1!
    \expandafter\index\expandafter{\temp!#2}%
  \else
    \expandafter\indexopt\expandafter{\temp!#2}{#1}
  \fi
}
\newcommand{\indexopt}[2]{\index[#2]{#1}}

\makeindex[title={Main Index},columns=1,program=texindy]
\makeindex[title={Name Index},columns=1,program=texindy,name=Name]
\indexsetup{level=\section}

\begin{document}

\AddIndexEntry{aardvark}{aardvark}
\AddIndexEntry{Saved by Zero}{Saved}
\AddIndexEntry{Saved by Zero}{Zero}
\AddIndexEntry[Name]{zero}{zero}

\clearpage % we want to be sure that all index entries are output
\setcounter{secnumdepth}{0}
\printindex

\printindex[Name]
\end{document}

The key is, however, to use \subsection for the letter groups, so that they will be children to the index. With \setcounter{secnumdepth}{0} we disable the numbering, and with \indexsetup{level=\section} we tell LaTeX to use \section{\indexname} instead of \section* so that the important actions by hyperref will be performed automatically.

share|improve this answer

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.