Follow up on How to create a shape for commenting a zone on a picture after answer of Claudio Fiandrino.
I have slightly modified the code and would like to compute the text width automatically.
\pgfkeys{/tikz/annotated figure/.cd,
start border pos/.initial={(0,0)},
start border pos/.get=\bpos,
start border pos/.store in=\bpos,
end border pos/.initial={(0,0)},
end border pos/.get=\epos,
end border pos/.store in=\epos,
border options/.code={
\tikzset{border style/.style={
#1
}
}
},
text options/.code={
\tikzset{text style/.style={
#1
}
}
},
}
\NewDocumentCommand{\xannote}{r[] m}{
\pgfkeys{/tikz/annotated figure/.cd,#1}
\node[coordinate] (x) at \bpos {};
\node[coordinate] (y) at \epos {};
\draw[border style] (x) rectangle (y);
\node[text style] at ($(x) !.5! (y)$) {#2};
}
Pgf is still obscur to me, I don't know how to do that, I tried to use
\pgfextractx{\mydim}{\pgfpointdiff{\epos}{\bpos}}
and set the text width with that but no success.
\pgfmathparse{width("text")}which stores the result then in the\pgfmathresultvariable as points (pt). – percusse Jun 05 '13 at 13:23