## LaTeX forum ⇒ General ⇒ Need a command to generate "above"/"below" in references

LaTeX specific issues not fitting into one of the other forums of this category.
sullivander
Posts: 3
Joined: Wed May 04, 2011 4:50 am

### Need a command to generate "above"/"below" in references

Greetings, first post here. I've searched forums (and the rest of the internet, it feels like) and can't find an answer to what seems like a simple question. I am trying to find a command that generates "above"/"below" as appropriate when referring to a label. As in, see the minimal working example "below".

I'm surprised that I cannot find such a command, as it seems like basic functionality. I'm trying to create one, and am going down the route of comparing \pageref{thelabel} and \thepage, but this obviously isn't guaranteed to work when the label and the reference are on the same page.

Any ideas? Either a pointer to an existing command, or a way to write a new one?

Many thanks,
Andrew

Minimal (sort of) Working Example:
\documentclass{article} \usepackage{ifthen} \newcommand{\locref}[1]{\ifthenelse{\pageref{#1}<\thepage}{above}{below}} \begin{document} % Here the command should resolve to "below" and doesCompared to this paragraph, the label is \locref{thelabel}. \clearpage % Here the command should resolve to "below" and doesCompared to this paragraph, the label is \locref{thelabel}. This paragraph is above the label. This paragraph contains the label.\label{thelabel} This paragraph is below the label. % Here the command should resolve to "above" but doesn'tCompared to this paragraph, the label is \locref{thelabel}. \clearpage % Here the command should resolve to "above" and doesCompared to this paragraph, the label is \locref{thelabel}. \end{document}

Tags:

Stefan Kottwitz
Posts: 9434
Joined: Mon Mar 10, 2008 9:44 pm
Hi Andrew,

welcome to the board! The varioref package provides similar features, for example references such as "on the previous page" or "above" if it falls onto the same page.

... see \vpageref[above]{label} ...

it's not the very same as in your question, however it may be useful for you. You could improve it if you like.

Stefan

sullivander
Posts: 3
Joined: Wed May 04, 2011 4:50 am
Hmm. Thanks for pointing out the varioref package, but it's not quite what I'm looking for: really just the simple words "above" or "below".

Stefan Kottwitz
Posts: 9434
Joined: Mon Mar 10, 2008 9:44 pm
Solving by referencing by labels is perhaps not the straigt solution. They are put in and used from the .aux file with page numbers. They are available after and also before their definition in text, in following compiling runs.

However, you could use a boolean variable, which is false and you set it to true at the required place in the text. Use an if command to check and to print out above resp. below if false resp. true.

Stefan

sullivander
Posts: 3
Joined: Wed May 04, 2011 4:50 am
Thanks! That's actually a really clever way to handle it.

Yeats
Posts: 62
Joined: Fri Nov 07, 2008 12:29 pm
Stefan_K wrote:Solving by referencing by labels is perhaps not the straigt solution. They are put in and used from the .aux file with page numbers. They are available after and also before their definition in text, in following compiling runs.

However, you could use a boolean variable, which is false and you set it to true at the required place in the text. Use an if command to check and to print out above resp. below if false resp. true.

Stefan

I am sorry to necro this old thread but I thought better that than making a new one with same discussion. I am not so advanced Latex user. Any chance that someone could explain me how I could do that?

My mentor wants me to have footnotes saying: Cf. below P. XX or Cf. above P. XX depending where the reference is.