8

Is there a way to find out and use the positioning choice (here, top, bottom, page) made for some figure?

Please spend a few minutes to admire 
\edef\mypos{\thepositioningchoicethatwasusedfor{myfig}}
\ifx\mypos h the following image:\fi
\ifx\mypos t \ref{myfig} at the top of page \pageref{myfig}.\fi
\ifx\mypos b \ref{myfig} at the bottom of page \pageref{myfig}.\fi
\ifx\mypos p \ref{myfig} residing on its own page \pageref{myfig}.\fi
\begin{figure}[htbp]
...
\label{myfig}
\end{figure}

I suppose I could play with \zref to make good guesses, but perhaps there is already something ready-made?

3
  • \label only records \@currentlabel (counter value), \@currentlabelname (varies), \@currentHref (hyperref target) and the page number. The placement options are implemented a bit flags in the float queue, but the hard part would be figuring out which insert corresponds to the given figure. May 26 at 14:08
  • 2
    It may be better to consider wordings of the following kind: "Figure X above/below" or "Figure Y on the previous/following page" or "Figure Z on page z"... rather than highlighting the location on the specific page; figures will have captions, which readers should... well.. read. varioref can help with the wording choices, as can zref's modules.
    – Werner
    May 26 at 23:54

1 Answer 1

4

Don't forget to run twice.

\documentclass{article}
\usepackage{refcount}

\makeatletter
\newcommand{\savefps}[1]% #1 = label name
{\bgroup
  \edef\@currentlabel{\number\@tempcnta}%
  \label{#1}%
\egroup}

\newcommand{\checkh}[3]{% #1 = bit flags, #2 = true, #3 = false
  \@tempcntb=#1\relax
  \ifodd\@tempcntb #2\relax
  \else #3\relax
  \fi}

\newcommand{\checkt}[3]{% #1 = bit flags, #2 = true, #3 = false
  \@tempcntb=#1\relax
  \divide\@tempcntb by 2
  \ifodd\@tempcntb #2\relax
  \else #3\relax
  \fi}


\newcommand{\checkb}[3]{% #1 = bit flags, #2 = true, #3 = false
  \@tempcntb=#1\relax
  \divide\@tempcntb by 4
  \ifodd\@tempcntb #2\relax
  \else #3\relax
  \fi}

\newcommand{\checkp}[3]{% #1 = bit flags, #2 = true, #3 = false
  \@tempcntb=#1\relax
  \divide\@tempcntb by 8
  \ifodd\@tempcntb #2\relax
  \else #3\relax
  \fi}
\makeatother

\begin{document}

\edef\foo{\getrefnumber{test}}% see refcount package
\checkh{\foo}{h}{not h}\par
\checkt{\foo}{t}{not t}\par
\checkb{\foo}{b}{not b}\par
\checkp{\foo}{p}{not p}\par

\begin{figure}[hp]
\savefps{test}
\end{figure}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.