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.

My LaTeX document contains an index which is also referenced in the table of contents via \addcontentsline. The page number displayed in the TOC is correct. The link, however, is not. (If I view the document structure in my PDF viewer, Evince, the page number also appears to be wrong.)

I found out that the link always seems to point to whatever is right before the index in the document structure (for example a section, subsection or paragraph).

In my example, the link generated by Pdflatex points to the paragraph "Und so weiter" which is right before the index. If I remove "Und so weiter" and compile again, the link will point to the subsection "Hallo".

Minimal working example

\documentclass[11pt, titlepage]{article}
\usepackage[ngerman]{babel}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{makeidx}
\usepackage{hyperref}

\pagestyle{plain}
\makeindex

\title{Stichwortverzeichnis bei \LaTeX\ korrekt verlinken}
\author{Kunigunde Knitterkleid}

%%%%% DOCUMENT %%%%%

\begin{document}
\maketitle

\setcounter{tocdepth}{3}
\tableofcontents
\thispagestyle{empty}
\clearpage

\section{Abschnitt 1}
\subsection{Blabla}
Lorem\index{Lorem|see{Lorem ipsum}} ipsum\index{Lorem ipsum} dolor sit amet, consectetuer adipiscing elit.
Donec ullamcorper, felis non sodales\index{sodales} commodo, lectus\index{lectus} velit ultrices augue, a dignissim nibh lectus placerat pede.
\clearpage

\section{Abschnitt 2}
\subsection{Hallo}
\paragraph{Und so weiter}
\blindtext
\clearpage

%%%%% INDEX %%%%%

\renewcommand{\indexname}{Stichwortverzeichnis}
\addcontentsline{toc}{section}{Stichwortverzeichnis}
\printindex

\end{document}

Oddly enough, it works perfectly when using a KOMA script class.

The only changes I made was changing the document class to scrartcl with the option index=totoc and removing the unnecessary \addcontentsline line.

Minimal working example using KOMA script

\documentclass[11pt, titlepage, index=totoc]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{makeidx}
\usepackage{hyperref}

\pagestyle{plain}
\makeindex

\title{Stichwortverzeichnis bei \LaTeX\ korrekt verlinken}
\author{Kunigunde Knitterkleid}

%%%%% DOCUMENT %%%%%

\begin{document}
\maketitle

\setcounter{tocdepth}{3}
\tableofcontents
\thispagestyle{empty}
\clearpage

\section{Abschnitt 1}
\subsection{Blabla}
Lorem\index{Lorem|see{Lorem ipsum}} ipsum\index{Lorem ipsum} dolor sit amet, consectetuer adipiscing elit.
Donec ullamcorper, felis non sodales\index{sodales} commodo, lectus\index{lectus} velit ultrices augue, a dignissim nibh lectus placerat pede.
\clearpage

\section{Abschnitt 2}
\subsection{Hallo}
\paragraph{Und so weiter}
\blindtext
\clearpage

%%%%% INDEX %%%%%

\renewcommand{\indexname}{Stichwortverzeichnis}
\printindex

\end{document}

Does anybody have any idea how I can make the link point to the correct location (apart from using KOMA script instead)?

I am using Tex Live 2009 on Linux.

share|improve this question
    
I'm still on Ubuntu 10.04 and this is the newest version of Tex Live in the repositories. I know I could get the latest version from tug.org, but I'm going to update my distro soon anyway, so I'll just deal with it at the moment. –  Anju Fabulina Jul 31 '12 at 12:10
add comment

1 Answer

up vote 4 down vote accepted

\addcontentsline doesn't set an achor; it just refers to the latest previous location where an anchor is set and that's why the hyperlink points to the wrong location (a sectional unit, in your case). To get the correct result, use \phantomsection from hyperref to set an anchor at the right location:

\phantomsection
\addcontentsline{toc}{section}{Stichwortverzeichnis}
\printindex

Another option is to use the tocbibind package:

\documentclass[11pt, titlepage]{article}
\usepackage[ngerman]{babel}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[nottoc]{tocbibind}
\usepackage{makeidx}
\usepackage{hyperref}

\pagestyle{plain}
\makeindex

\title{Stichwortverzeichnis bei \LaTeX\ korrekt verlinken}
\author{Kunigunde Knitterkleid}

%%%%% DOCUMENT %%%%%

\begin{document}
\maketitle

\setcounter{tocdepth}{3}
\tableofcontents
\thispagestyle{empty}
\clearpage

\section{Abschnitt 1}
\subsection{Blabla}
Lorem\index{Lorem|see{Lorem ipsum}} ipsum\index{Lorem ipsum} dolor sit amet, consectetuer adipiscing elit.
Donec ullamcorper, felis non sodales\index{sodales} commodo, lectus\index{lectus} velit ultrices augue, a dignissim nibh lectus placerat pede.
\clearpage

\section{Abschnitt 2}
\subsection{Hallo}
\paragraph{Und so weiter}
\blindtext
\clearpage

%%%%% INDEX %%%%%

\renewcommand{\indexname}{Stichwortverzeichnis}

\printindex

\end{document}
share|improve this answer
    
Thank you very much, using \phantomsection worked! Yes, I just read the description for \phantomsection in the hyperref documentation and now I know why it's always the last section-like thing the link points to: "\addcontentsline refers to the latest previous location where an anchor is set." –  Anju Fabulina Jul 30 '12 at 16:40
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.