6

I would like to have an easy way to reference a label and if that label is not on the current page then its page should be printed in the reference like "See example 2.3 (p.4)". I tried the varioref and the cleveref packages but their text output using \vref or \cref is too verbose for me. I couldn't find anything in the documentation to just print (p.4) instead. Or is there another alternative?

  • Why couldn't you "find anything in the documentation"? Where did you look? Section 3 "Customization" of varioref.pdf has all the details. – Frank Mittelbach Aug 28 '13 at 19:20
  • I saw that but couldn't figure out that this section with its non-existing examples is what I'm looking for. – user764754 Aug 28 '13 at 20:37
4

If you are using babel you can change the printed reference with package varioref as shown in the following MWE for German language.

\documentclass[ngerman]{scrartcl}% article

\usepackage{babel}
\usepackage{varioref}
\usepackage{blindtext}
\usepackage[colorlinks]{hyperref} 

\addto{\extrasngerman}{% addto only with babel  <===============
  \renewcommand{\reftextfaceafter}[1]{(Seite~\pageref{#1})}
  \renewcommand{\reftextfacebefore}[1]{(Seite~\pageref{#1})}
  \renewcommand{\reftextafter}[1]{(Seite~\pageref{#1})}
  \renewcommand{\reftextbefore}[1]{(Seite~\pageref{#1})}
  \renewcommand{\reftextcurrent}[1]{(Seite~\pageref{#1})}
  \renewcommand{\reftextfaraway}[1]{(Seite~\pageref{#1})}
}


\begin{document}

\section{Abschnitt 1}
\label{sec:Test}

Und der erste Verweis auf Abschnitt~\vref{sec:Test}. %  <===============

\Blinddocument

Und der Verweis auf Abschnitt~\vref{sec:Test}.       %  <===============

\end{document} 

The macro \addto{\extrasngerman} adds the new meanings for language ngerman. If you use another language change ngerman to your language.

Change (Seite~\pageref{#1}) to that you need, for example (p.~\pageref{#1}).

Edit:

The KOMA-Script macro \newcaptionname{ngerman}{...} is not able to handle a third argument (for \pageref{#1}) so you can't use it here.

  • Perfect. One thing that is strange is that i get errors like "Extra \else." when I keep using cleveref. – user764754 Aug 28 '13 at 0:03
  • @user764754 errors might be due to the order you load packages (or not all of them up-to-date): hyperref, babel and cleveref all overwrite some of the varioref definitions. – Frank Mittelbach Aug 28 '13 at 19:18
6

If you use varioref all the fixed texts are in easily changable macros, for example the package has

    \def\reftextfaraway#1{on page~\pageref{#1}}%

so you can have

    \renewcommand\reftextfaraway[1]{p.~\pageref{#1}}%

and similarly for any other texts it produces.

  • Thanks! What worked for me was \addto\extrasngerman{\renewcommand{\reftextfaraway}[1]{(p.\pageref{#1})}} – user764754 Aug 27 '13 at 23:19
  • 1
    @user764754 this is needed because Babel is used. All of that is documented in varioref.pdf (section 3). – Frank Mittelbach Aug 28 '13 at 19:16

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.