Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When a cross-reference to a figure is not on the same page as the figure, I would like to include the page number in the figure. But when they are on the same page, this is redundant--and I want to omit the page number.

In other words, I want to switch between these two styles of figure referencing depending on samepage/differentpage:

\newcommand{\figref}[1]{Figure~\ref{fig:#1}, page \pageref{fig:#1}}
\newcommand{\simplefigref}[1]{Figure~\ref{fig:#1}}

Probably Testing for current page and conditionals can do this, has anybody got a recipe worked out?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

Try the varioref package.

\documentclass[english]{scrartcl}

\usepackage{babel}
\usepackage{varioref}

\usepackage{blindtext}% just for testing

\begin{document}
Text \vref{fig1}. \blindtext

\blindtext[5]% change this number to see
             % the different outputs of \vref

\begin{figure}
  \rule{2cm}{2cm}
  \caption{Text}\label{fig1}
\end{figure}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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