[Tex/LaTex] Get actual position

beamerposterfloatspositioningvertical alignment

Is there any command to get current position in text?
What do I mean:

\the\currentposition
text text text text \newline
\the\currentposition
text text text text \newline
\the\currentposition

Output:
0pt
text text text text
12pt
text text text text
24pt

Or even better – how to get actual (x,y) position of some text or enviroment (i.e. top left corner of column or block) in the list?

Best Answer

pdfTeX in PDF mode provide \pdfsavepos, which stores the current position that can be written to the .aux file and used the next TeX run. Also XeTeX and LuaTeX provide this features. There are some limitations:

  • XeTeX's right to left mode is somewhat broken.
  • Graphics state changes, that do not use the pdfTeX interfaces (\pdfsetmatrix, \pdfsave, \pdfrestore) interfere with the position recording.

  • Absolute values are not well defined, thus relative values are preferred.

Package zref-savepos of project zref provides an interface to the positioning feature:

\documentclass{article}
\usepackage{zref-savepos}

\newcommand*{\currpos}[1]{%
  \zsavepos{#1}%
  (\zposx{#1}sp, \zposy{#1}sp) =
  (\the\dimexpr\zposx{#1}sp\relax, \the\dimexpr\zposy{#1}sp\relax)%
}

\begin{document}
\leavevmode
\currpos{posA}
text text text text \newline
\currpos{posB}
text text text text \newline
\currpos{posC}
\end{document}

Result after two compile runs:

Result