Text FormattingLinking to wrong page

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Linking to wrong page

Post by svend_tveskaeg »

Hi all.

Consider the following MWE:

Code: Select all

\documentclass{article}

\usepackage{hyperref}

\begin{document}

\pagenumbering{roman}

First page.
\newpage

\pagenumbering{arabic}

See \autopageref{horse}.
\newpage

Something.
\label{horse}

\end{document}
The printed text on the second page (i.e., ``See page 2.'') is correct. However, the link on the second page is linking to the first page (i.e., page i) and not third page (i.e., page 2) as it should.

How do I fix this?

Thank you in advance!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Linking to wrong page

Post by kaiserkarl13 »

The \label command defines a key that refers to the last generated a number (and the page it was generated on). For example, consider this:

Code: Select all

\section{Hello}
% lots o' text
\begin{table}
  \label{mykey}
  \caption{Caption text.}
  % table contents
\end{table}
Using \pageref{mykey} would generate the page number of whatever page the "Hello" section happened to start on. It would NOT refer to the page on which the \label command appeared, nor would it refer to the label on which the table appeared unless you moved the \label AFTER the caption, since \caption generates a number!

If you want to refer to an arbitary page number, insert something like this:

Code: Select all

\newcounter{dummy}
\refstepcounter{dummy}
\label{mykey}
Now \pageref{mykey} and relatives will refer to the page on which the \refstepcounter command was issued.
Post Reply