1

When I type \ref{name} giving the link is on the wrong page. How do I fix this?

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{theorem}

\newtheorem{teo}{Teorema}[chapter]
\begin{document}
\begin{teo}\label{tvi}
text
\end{teo}
... %insert various \newpage
\ref{tvi}
\end{document}

Returns incorrect page.

Regis Santos
  • 14,463
  • 6
    Please post a full minimal example. – Joseph Wright Sep 25 '11 at 20:14
  • 5
    Does teo include a \refstepcounter? Otherwise the \label might point to the last label-able item (e.g. section) instead. – Martin Scharrer Sep 25 '11 at 20:21
  • 2
    You are talking about links, but your code doesn't show you load hyperref; also teo doesn't exist in standard LaTeX, so you have to show its definition. – egreg Sep 25 '11 at 20:32
  • Your revised example works for me (link pointing to the correct page). – lockstep Sep 25 '11 at 20:44
  • Yes lockstep, but in my file, using latex file.tex thus page is incorrect link. – Regis Santos Sep 25 '11 at 20:46
  • 2
    The theorem package is obsolete, all its functionality is present in ntheorem. Apart from this, I don't see any problem and after adding \lipsum paragraphs I always get the correct link. – egreg Sep 25 '11 at 20:56
  • 2
    You mention that the link jumps to an "incorrect page". Do you perhaps have another object using the label tvi? You'll know this is the case your log file contains the output "LaTeX Warning: There were multiply-defined labels." near the end. – Werner Sep 25 '11 at 21:42

2 Answers2

3

Your example works fine for me.

cmhughes
  • 100,947
1

Your example works fine for me.

  • Follow the advice given by cmhughes
  • Did you compile your document at least twice? Check for any rerun warnings in the log-file, e.g.

    LaTeX Warning: Reference `tvi' on page ... undefined on input line 34.

    Package rerunfilecheck Warning: File `....out' has changed.

    (rerunfilecheck) Rerun to get outlines right

    (rerunfilecheck) or use package `bookmark'.

    LaTeX Warning: There were undefined references.

    LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

  • Place a \phantomsection before \begin{teo}.

Where does the link in your example lead to? The page before or after the \begin{teo}, to the first page of your document, ...?

Stephen
  • 14,890