LaTeX forum ⇒ GeneralNeed 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

Postby sullivander » Wed May 04, 2011 5:26 am

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:
  1. \documentclass{article}
  2.  
  3. \usepackage{ifthen}
  4.  
  5. \newcommand{\locref}[1]{\ifthenelse{\pageref{#1}<\thepage}{above}{below}}
  6.  
  7. \begin{document}
  8.  
  9. % Here the command should resolve to "below" and does
  10. Compared to this paragraph, the label is \locref{thelabel}.
  11.  
  12. \clearpage
  13.  
  14. % Here the command should resolve to "below" and does
  15. Compared to this paragraph, the label is \locref{thelabel}.
  16.  
  17. This paragraph is above the label.
  18.  
  19. This paragraph contains the label.\label{thelabel}
  20.  
  21. This paragraph is below the label.
  22.  
  23. % Here the command should resolve to "above" but doesn't
  24. Compared to this paragraph, the label is \locref{thelabel}.
  25.  
  26. \clearpage
  27.  
  28. % Here the command should resolve to "above" and does
  29. Compared to this paragraph, the label is \locref{thelabel}.
  30.  
  31. \end{document}

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 9440
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed May 04, 2011 11:20 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.

  1. ... 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
Site admin

sullivander
Posts: 3
Joined: Wed May 04, 2011 4:50 am

Postby sullivander » Thu May 05, 2011 1:09 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".

User avatar
Stefan Kottwitz
Site Admin
Posts: 9440
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Thu May 05, 2011 9:35 am

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
Site admin

sullivander
Posts: 3
Joined: Wed May 04, 2011 4:50 am

Postby sullivander » Sun May 08, 2011 6:42 pm

Thanks! That's actually a really clever way to handle it.

Yeats
Posts: 62
Joined: Fri Nov 07, 2008 12:29 pm

Postby Yeats » Wed Dec 04, 2013 3:37 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.


Return to “General”

Who is online

Users browsing this forum: No registered users and 14 guests