I know this can be considered as duplicate question. I'm not here to find solution for it. I asked this question just to argue about reliability of pageref. I mean, why this malfunctioning happens so often? Are there any technical issues behind it?

I faced it while typesetting the 'latex-second-d.tex' file found in 'first-latex-doc.zip' came from an article "first-latex-doc – A document for absolute LATEX beginners" on https://ctan.org/pkg/first-latex-doc.

Instead of 2, it produced 3 while still 'Goto page 2' (as expected) when we clicked on it, Why?
Here is the code: (I'm using TeXworks ver 0.6.2)


\title{Test document}
\author{Your name \\ \url{you@example.com}}

This is some preamble text that you enter 
yourself.\footnote{First footnote.}\footnote{Second footnote.}

\section{Text for the first section}

\subsection{Text for a subsection of the first section}

\subsection{Another subsection of the first section}

\section{The second section}

Refer again to \ref{labelone}.\cite{ConcreteMath}
Note also the discussion on page \pageref{labeltwo}

\subsection{Title of the first subsection of the second section}

Ronald L. Graham, Donald E. Knuth, and Oren Patashnik, 
\textit{Concrete mathematics}, 
Addison-Wesley, Reading, MA, 1995.

A snap of it's output:
enter image description here

  • You need to place label immediately after \section. Or use \phantomsection if want link to page 3 – daniel Sep 25 '18 at 20:01

The command \pageref behaves as designed: It produces the page number of the place where the corresponding \label appeared, and not the place where the previous \refstepcounter (triggered by \subsection in the example) appeared. If you want it to produce the latter page number, place it right after the \section command.

The hyperref package muddies the water, however. It uses different mechanisms to achieve its goals, and so it links to the subsection instead of the place where the \label occurred.

If you want the latter, you need to make your own hypertarget: \hypertarget{somename}{some contents}\label{labeltwo}.

Then at the place of reference, use \hyperlink{somename}{\pageref*{labeltwo}}.

  • I agreed with you. One more thing, i don't understand why they've put bad code on the very first tutorial like that. This really confuses new learners who will run into problem at the first time they try executing the code. – Tai Le Sep 28 '18 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.