# Incorrect reference

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.

-
Please post a full minimal example. –  Joseph Wright Sep 25 '11 at 20:14
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
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
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
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

Your example works fine for me.

• Make sure that your packages are up to date; you can check which version you have by adding \listfiles immediately before your \begin{document}
• You should generally load the hyperref package last; there some exceptions discussed here: Which packages should be loaded after hyperref instead of before?
-

Your example works fine for me.

• 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, ...?

-