3

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.

Penbeuz
  • 1,669
  • Not the direct answer but you can use the \pgfmathparse{width("text")} which stores the result then in the \pgfmathresult variable as points (pt). – percusse Jun 05 '13 at 13:23

1 Answers1

1

Claudio Fiandrino has improved his code and given a good answer in How to create a shape for commenting a zone on a picture. .

Penbeuz
  • 1,669