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?


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.

  • 1
    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}}]; 
  • 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


Your Answer

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