TransWikia.com

How to get hyperref to link to the index

TeX - LaTeX Asked by Michael Barr on July 11, 2021

I am trying to get hyperref link to the actual page that the index starts. It follows the Bibliography by several pages, but when you click on Index in the TOC, you are taken to the first page of the bibliography. The option hyperindex makes the index entries linkable and that is very nice, but the title Index is supplied by printindex and I have not been able to figure out to modify it.

The way I get the link to the Biblio is

chapter*{Bibliography}
addcontentsline{toc}{chapter}{Bibliography}

Sample file:

documentclass{book}
 usepackage{index,multicol}
 usepackage[nosort,nocompress]{cite}
 usepackage[hyperindex]{hyperref}
makeindex
begin{document}
tableofcontents
chapter*{Preface}
 addcontentsline{toc}{chapter}{Preface}
This is a very brief preface.
 chapter{This is the first chapter}
 section{Here is the first section}
 Here we have Section 1 index{Section 1}
Here is a bibliographical reference cite{Kn1,Kn2}.
 section{Here is the second section}
 Here is Section 2 index{section 2}
begin{thebibliography}{Kn2}
 addcontentsline{toc}{chapter}{Bibliography}
 bibitem{Kn1}D.E. Knuth, AOCP 1
 bibitem{Kn2}D.E. Knuth, AOCP 2
end{thebibliography}
printindex
end{document}

Note that in the real book, adding addtocontentsline after the printindex would put the pointer in the wrong place.

One Answer

You need to add a phantomsection as anchor, if the relevant command doesn't do this internally. In your case I would suggest to use imakeidx and tocbibind, to simplify the code:

documentclass{book}
usepackage{tocbibind}
usepackage{imakeidx}
usepackage[nosort,nocompress]{cite}
usepackage[hyperindex]{hyperref}

makeindex[intoc]

begin{document}
tableofcontents
cleardoublepagephantomsection
chapter*{Preface}
 addcontentsline{toc}{chapter}{Preface}
This is a very brief preface.
 chapter{This is the first chapter}
 section{Here is the first section}
 Here we have Section 1 index{Section 1}
Here is a bibliographical reference cite{Kn1,Kn2}.
 section{Here is the second section}
 Here is Section 2 index{section 2}
begin{thebibliography}{Kn2}
 bibitem{Kn1}D.E. Knuth, AOCP 1
 bibitem{Kn2}D.E. Knuth, AOCP 2
end{thebibliography}

printindex
end{document}

Answered by Ulrike Fischer on July 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP