# How to change cleveref references to 'verbal' varioref style?

I would like to use cleveref's automatic ref target type recognition but with the more verbal page reference of varioref. This is my MWE:

\documentclass{report}
\usepackage{varioref}
%\usepackage{cleveref}     % note cleveref package changes type of ref..
% and style of references to last/next page
\begin{document}

% This figure appears on page 1.
\begin{figure}[!htb]
\centering
\rule{24pt}{24pt}
\caption{The famous black square}
\label{OneBlackSquare}
\end{figure}

% This sentence appears on page 2.
\clearpage
The non-color black is shown in \vref{OneBlackSquare}.

\end{document}


It produces a nice to read verbal reference when using the varioref package:

The only thing missing is the automatic target type. Enabling the cleveref package adds this very good feature but also overrides all verbal behavior of varioref. Regardless of the space to the target all references are located by page number instead of "on next page".

But how can I combine them to get:

1. the automatic target type like figure or equation of cleveref and
2. the verbal description of the target's position if it is on the last/next page to improve the reader's flow?

Edit after a week: I received no solution proposal and both documentation do not solve my problem. Hence I stick with varioref and write the type of floating object hard coded in the text.

• Very strange. It works if the figure comes on the next page: "The non-color black is shown in fig. 2 on the next page." – Juri Robl Jul 6 '14 at 16:39
• I know from reading the documentation of cleveref, that it overwrites varioref positioning expressions. Is there a way to change cleveref expressions back again? – VisorZ Jul 7 '14 at 14:05

A nice bug! There is a space character missing in the cleveref package. Line 2337 currently reads:

        \advance\@tempcnta-2%


        \advance\@tempcnta-2 %


yes, it is that space character (see What are the differences between TeX counts and LaTeX counters?).

I have notified Toby Cubitt, but for now you can either fix your package source locally, or overwrite the change in your preamble as follows:

\documentclass{report}
\usepackage{varioref}
\usepackage{cleveref}

\makeatletter
\def\cref@old@@vpageref#1[#2]#3{%
\leavevmode%\unskip  <<<
\vref@pagenum\@tempa{\the\c@vrcnt @vr}%
\vref@pagenum\@tempb{\the\c@vrcnt @xvr}%
%\vref@label{\the\c@vrcnt @xvr}%  <<<
\ifx\@tempa\@tempb\else%
\vref@err{\noexpand\vref or \noexpand\vpageref at page boundary
\@tempb-\@tempa\space (may loop)%
}%
\fi%
\vrefpagenum\thevpagerefnum{#3}%
\vref@space%
\ifx\@tempa\thevpagerefnum%
\def\@tempc{#1}%
\ifx\@tempc\@empty%
\unskip%
\else%
#1%
\fi%
\else%
#2%
\is@pos@number\thevpagerefnum%
{%
\is@pos@number\@tempa%
{\@tempcnta\@tempa%
}%
{\@tempcnta\maxdimen}%
\ifnum \thevpagerefnum =\@tempcnta%
\ifodd\@tempcnta%
\if@twoside%
\reftextfaceafter%
\else%
\reftextafter%
\fi%
\else%
\reftextafter%
\fi%
\else%
\advance\@tempcnta-2 %  <--- there was a space missing here!
\ifnum \thevpagerefnum =\@tempcnta%
\ifodd\@tempcnta%
\reftextbefore%
\else%
\if@twoside%
\reftextfacebefore%
\else%
\reftextbefore%
\fi%
\fi%
\else%
\reftextfaraway{#3}%
\fi%
\fi%
}%
{\reftextfaraway{#3}}%
\fi%
\vref@label{\the\c@vrcnt @xvr}%  <<<
\vref@label{\the\c@vrcnt @vr}%
}%
\makeatother

\begin{document}

% This figure appears on page 1.
\begin{figure}[!htb]
\centering
\rule{24pt}{24pt}
\caption{The famous black square}
\label{OneBlackSquare}
\end{figure}

% This sentence appears on page 2.
\clearpage
The non-color black is shown in \vref{OneBlackSquare}.

\end{document}


This gives the expected:

The non-color black is shown in Fig. 1 on the preceding page.

• Your solution works. To implement the bug fix I changed line 2337 in /usr/local/texlive/2014/texmf-dist/tex/latex/cleveref/cleveref.sty. My LaTeX distribution is TexLive 2014 on Mac OSX. That alone resulted in the correct referencing. Additionally I changed line 5932 in /usr/local/texlive/2014/texmf-dist/source/latex/cleveref/cleveref.dtx, to keep the documentation in sync. – VisorZ Apr 29 '15 at 6:45