确定图形的位置是 h、t、b 还是 p

确定图形的位置是 h、t、b 还是 p

有没有办法找出并使用定位选择(H这里,op,b奥托姆,年龄)适合某些人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}

我想我可以尝试\zref猜测一下,但也许已经有现成的东西了?

答案1

别忘了跑两次。

\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}

相关内容