[Tex/LaTex] \widthof within tikzpicture


In this minimal example





    \setlength{\TestLength}{\widthof{\tikz \node {bla};}} 
    \showthe\TestLength% MEASUREMENT 1 

            \setlength{\TestLength}{\widthof{\node {bla};}} 
            \showthe\TestLength% MEASUREMENT 2 


\TestLength is calculated correctly in the first time (MEASUREMENT 1), but too small in the second time (MEASUREMENT 2). I'd like to calculate it within a tikzpicture environment, so that I'm fixed to the second way of calculation. is there any workaround?

Thanks a lot for any kind of comments or ideas.

Best Answer

If you want to measure the size of a node that has already been typeset and named, you can use the following code:



% \getwidthofnode will measure the width of the node given as its second
% parameter and store it into the first parameter.
    \pgfextractx{\pgf@xa}{\pgfpointanchor{#2}{west}}% \pgf@xa is a length defined by PGF for temporary storage. No need to create a new temporary length.


    \node (mynode) {bla};