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.

In the following code, the command \label{my} appears on page 4, as well \pageref{my} says "4", but the hyperlink points to the page one. Why is that?

\documentclass{book}
\usepackage{hyperref}
\usepackage{lipsum}

\begin{document}

  % Four pages of text.
  \lipsum[1-20] 

  % The label is on fourth page.
  \label{my}    

  % Buggy pageref. It produces the number 4, but the link leads to the first page.
  \pageref{my} 

\end{document}
share|improve this question
5  
Most definitely not a bug. The \label command attaches a marker to the nearest structure -- \section, \caption, etc -- that can receive an anchor. Your document has no anchorable structures at all; hence the default anchor, the start of the document, applies. Use the \pantomsection command to create additional anchors for \label commands. –  Mico Mar 23 '12 at 3:05

1 Answer 1

up vote 20 down vote accepted

It's not a bug; there's no anchor; \label by itself does not place an hyperlink-anchor, so obviously your hyperlink won't take you to the place where you placed \label; you can use \phantomsection to create an anchor at a given location:

\documentclass{book}
\usepackage{hyperref}
\usepackage{lipsum}

\begin{document}

\lipsum[1-20] 

\phantomsection\label{my}\newpage 

\pageref{my} 

\end{document}
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.