In my experience, using several packages which enhance cross referencing in LaTeX, leads to problems or odd behavior. Luckily modern versions of varioref
is able to do some of the things cleveref
can as well and, depending on your exact needs, it may not be necessary to use both packages.
If you are looking for a single macro, which will output "section 1.2", "section 1.2 on the next page", "section 1.2 on page 14", "chapter 4 on page 51", "equation (2.5) on the facing page", etc. depending on what the \label
references and where \label
and \ref
is placed, varioref
should be enough. With
\usepackage{varioref}
\labelformat{chapter}{chapter~#1}
\labelformat{section}{section~#1}
\labelformat{equation}{equation~(#1)}
in the preamble, \vref{label}
will result in the output above and there should be no need for a custom macro. Please note, that \vref
will print a space before the reference and that the space will be suppressed if using \vref*
instead. If you start a sentence with a reference and therefore need the first letter capitalized, use \Vref
.
I you prefer "on page 11" to "on the next page" for every reference, you should include the following lines from lockstep's answer in your preamble.
\renewcommand\reftextfaceafter{on page~\thevpagerefnum}
\renewcommand\reftextfacebefore{on page~\thevpagerefnum}
\renewcommand\reftextafter{on page~\thevpagerefnum}
\renewcommand\reftextbefore{on page~\thevpagerefnum}
cleveref
has features that varioref
lacks, such as referencing ranges, and according to the author of cleveref
it should be able to replace varioref
entirely. From the cleveref
manual:
The enhanced referencing feature provided by the varioref package's \labelformat command decides how to format cross-references when the label is defined, rather than when it is referenced. Often this isn’t a problem. But it makes it impossible to format cross-references differently according the context in which they are referenced, which can sometimes be very useful. For example, if you want cross-references at the beginning of a sentence formatted any other way than by capitalising the first letter of the cross-reference text, it is impossible using varioref. E.g. you may want to use the abbreviation “eq.”, but revert to "Equation" at the beginning of sentences (words at the start of sentences shouldn’t be abbreviated in English). This is not possible with varioref. Perhaps even more significantly, varioref’s \labelformat implementation makes it impossible to typeset multiple references automatically; if you want to refer to equations eq1 through eq3, with varioref you are back to typing Eqs.~(\ref{eq1}) to~(\ref{eq3}) by hand. Not to mention missing out on all the other cleveref features. In fact, cleveref fully supports varioref, taking over responsibility for typesetting cross-references, whilst retaining (and even enhancing) all the varioref page-referencing magic.
I myself have not had use for the features of cleveref
and find varioref
easier to use.