3

I am linking to pages. I can refer to pages that are located before, but I can’t link to page 3 to find two on page. Why is that? How to fix? thank!

  \documentclass[a4paper]{article} % Размер бумаги и стиль документа (книга, журнал,...)
    \usepackage[14pt]{extsizes} % Размер шрифта
    \usepackage{cmap} % поиск в PDF
    \usepackage[T2A]{fontenc} % кодировка
    \usepackage[utf8]{inputenc} % кодировка исходного текста
    \usepackage[english,russian]{babel} %локализация и переносы
    \usepackage{caption}
% подключаем hyperref (для ссылок внутри  pdf)
\usepackage[unicode, pdftex, colorlinks=true, linkcolor=blue]{hyperref}
%\newcommand{\стр}[1]{стр.~\pageref{#1}}

\begin{document}

Здесь описан процесс создания ссылки\label{L} подробно описан здесь.
    \newpage
как мы уже отмечали на стр.~\pageref{L} говорится о...
Однако, как будет показано далее, на стр..~\pageref{units} это всё неправда.


\newpage 
Однако здесь\label{units} сказано совершенно о другом.

\end{document}

2 Answers2

7

It would be nice if \pageref would automatically jump to the right page. But the current label/ref system of LaTeX is a bit restricted. hyperref can store only one destination name and this is used for the current counter, so there is no place for the page destination.

So currently you can either add \phantomsection before your \label, then the link will jump to this position:

\documentclass[a4paper]{article}
 \usepackage{hyperref}
  \begin{document}

first page

wrong: \pageref{units}, right: \pageref{units2} \newpage second page \label{units}\phantomsection\label{units2}

\end{document}

Or with an extended reference system like zref one could also store the page destination:

\documentclass[a4paper]{article}     
 \usepackage{hyperref}
 \usepackage{zref-base,zref-user}
 \makeatletter
 \zref@newprop*{pagedest}[Doc-Start]{page.\@the@H@page}
 \zref@addprop{main}{pagedest}
 \newcommand\hyperpageref[1]{\hyperlink{\zref@extract{#1}{pagedest}}{\pageref*{#1}}}
 \makeatother
 \begin{document}

first page

wrong: \pageref{units}, right: \hyperpageref{units} \newpage second page \label{units}\zlabel{units}

\end{document}

Ulrike Fischer
  • 327,261
3

By default you cannot simply use \label to mark a label on page without any previous counter stepping. hyperref do creates one pdf link for every page, but the position of those links are always located at the upper-left corner of page. See an example.

Therefore to allow variable link position and auto page reference, here I create a dummy counter @page stepped by new command \pagelabel. You can use \pagelabel{<label name>} to create a "label on page", and then use \pageref{<label name>} to refer to it.

\documentclass[a4paper]{article} % Размер бумаги и стиль документа (книга, журнал,...)
\usepackage[14pt]{extsizes} % Размер шрифта
\usepackage{cmap} % поиск в PDF
\usepackage[T2A]{fontenc} % кодировка
\usepackage[utf8]{inputenc} % кодировка исходного текста
\usepackage[english,russian]{babel} %локализация и переносы
\usepackage{caption}

% подключаем hyperref (для ссылок внутри pdf) \usepackage[unicode, pdftex, colorlinks=true, linkcolor=blue]{hyperref} %\newcommand{\стр}[1]{стр.~\pageref{#1}}

\newcounter{@page} \newcommand*{\pagelabel}{\refstepcounter{@page}\label}

\begin{document} Здесь описан процесс создания ссылки\pagelabel{L} подробно описан здесь. \newpage

как мы уже отмечали на стр.~\pageref{L} говорится о... Однако, как будет показано далее, на стр..~\pageref{units} это всё неправда. \newpage

Однако здесь \pagelabel{units}сказано совершенно о другом.
\end{document}

muzimuzhi Z
  • 26,474