# How to mix \ref{} and \pageref{}?

There is \ref{} and \pageref{}. But I want mixed behaviour. I would like to have something like "XXX (page.YYY)" in text, where XXX is what \ref{} usually produce (chapter/section/etc number), while YYY is page number. How to do it?

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
– user31729
Feb 15 '15 at 18:04
• Think about how this should work if the \ref points to something on the same page... Feb 15 '15 at 18:08

create a new command like \fullref

\newcommand{\fullref}[1]{%
\ref{#1}
(p.~\pageref{#1})%
}


And call

\fullref{label}


That is a MWE which doesn't test page. I suggest, as @Mico said, to use https://www.ctan.org/pkg/varioref. The author of the package has thought to you :-)

• Thanks! I need to learn basic macro processing in TeX :) Feb 15 '15 at 18:07
• Possibly better with p.~\pageref{#1} Feb 15 '15 at 18:10
• that is LaTeX, not tex. You will find easily on internet the basic of \newcommand. Here, we have a command with only one argument. We send it (#1) to other commands. Feb 15 '15 at 18:10
• inded, egreg you are true Feb 15 '15 at 18:11
• or \cpageref{#1} with cleveref
– user31729
Feb 15 '15 at 18:11

I suggest you look into the varioref package and its \vref macro. The macro has the following properties:

• if the item being cross-referenced happens to be located on the same page, it behaves like the plain \ref macro, i.e., nothing is appended;

• if the item is located on the immediately previous or following page, it appends "on the preceding page" or "on the following page", as appropriate, to the cross-reference;

• if the item is located somewhere else in the document, the string "on page " is appended to the cross-reference.