TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I have some .tex code like this

bla bla \framebox{Hello World} bla bla

I want to read out the position (left and top or bottom, in pts) of the framebox on the page, and store in, say, variables \myleft, \myright.

It would also be enough to read out the current position on the page. (I want to highlight the box later in another program, so I need to know its absolute position in the produced pdf.)

Synctex seems to be able to do that, so it should be possible... but how?

share|improve this question
up vote 7 down vote accepted

You can use the \zsavepos macro of the zref package. Note you need to LaTeX twice before you have the position accurately.


\zsavepos{XY}\fbox{Testing }

\zposx{XY}, \zposy{XY} 



\X, \Y

Edit: show minimal using fp package for calculations.

share|improve this answer
That works very well, thanks for the very quick answer! – user3362 Feb 5 '11 at 19:44

You could use the functionality of TikZ and its remember picture option. It needs two compile runs.



\tikz[remember picture]\node(x){\framebox{Test}};

% Later
% There are better ways to do this, I'm sure:
  \path let \p0 = (x.north west) in
  % \x0, \y0 hold the position from the lower left page corner
  [/utils/exec={\message{x = \x0, y = \y0}}]; 
share|improve this answer
Thanks a lot! Your code helped me as well, though I'll go with Yiannis' answer. – user3362 Feb 5 '11 at 19:47
@Thomas: You are welcome, and no problem, zref seems to be the right way to do it. I didn't know it before by myself. – Martin Scharrer Feb 5 '11 at 19:52

It needs two pdflatex runs



bla bla \zsavepos{fbox}\framebox{Hello World} bla bla


the fbox starts at (\zposx{fbox}sp;\zposy{fbox}sp), which is the same
as (\the\numexpr \zposx{fbox}/65536\relax pt; 
    \the\numexpr \zposy{fbox}/65536\relax pt), 
always measured from the left and bottom of the page

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.