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

After adding support for tooltips today in pdfcomment (\pdftooltip) I wanted to make a TikZ example with tooltip annotations. Within \pdftooltip the annotated element is set into a box to measure the size, which does not work for parts of a TikZ graphic. There are workarounds (manual box or \textbullet) in the following example:

% http://svn.berlios.de/viewvc/pdfcomment/trunk/dev/tex/latex/pdfcomment/pdfcomment.sty?revision=11
    % Draw axes
    \draw [<->,thick] (0,2) node (yaxis) [above] {$y$}
        |- (3,0) node (xaxis) [right] {$x$};
    % Draw two intersecting lines
    \draw (0,0) coordinate (a_1) -- (2,1.8) coordinate (a_2);
    \draw (0,1.5) coordinate (b_1) -- (2.5,0) coordinate (b_2);
    % Calculate the intersection of the lines a_1 -- a_2 and b_1 -- b_2
    % and store the coordinate in c.
    \coordinate (c) at (intersection of a_1--a_2 and b_1--b_2);
    % Draw lines indicating intersection with y and x axis. Here we use
    % the perpendicular coordinate system
    \draw[dashed] (yaxis |- c) node[left] {$y'$}
        -| (xaxis -| c) node[below] {$x'$};
    % Draw a dot to indicate intersection point
    %% 1 - add a box manually %%
    \fill[red] (c) circle (2pt);
    \draw (c) node {\pdftooltip{\rule{0pt}{5pt}\rule{5pt}{0pt}}{This is the intersection point\textCR of the two lines!}};
    %% 2 - use \textbullet, which produxes a size in a box %%
    %\draw[red] (c) node {\pdftooltip{\textbullet}{This is the intersection point\textCR of the two lines!}};
    %% 3 - produces an error %%
    % "\fill[red] (c) circle (2pt);" can not be put in a box to measure the size
    %\pdftooltip{\fill[red] (c) circle (2pt);}{This is the intersection point\textCR of the two lines!}}    

graphic with tooltip annotation

Is there a way that part of a TikZ graphic does produce a size when set into a box?

share|improve this question
The required pdfcomment version seems to not be on CTAN yet. Could you provide an alternative download link in the meantime? – Martin Scharrer May 19 '11 at 17:37
@ Martin Scharrer It's in the example ;-) svn.berlios.de/viewvc/pdfcomment/trunk/dev/tex/latex/pdfcomment/… – Josef May 19 '11 at 17:42
Aaaah, you mean this hard to read gray-on-gray text? ;-) – Martin Scharrer May 19 '11 at 17:43
@Martin Scharrer Exactly! ;-) – Josef May 19 '11 at 17:45
up vote 3 down vote accepted

I would make the tooltip part of the path. Then you can access the paths bounding box using current path bounding box and measure its dimensions.

\fill[red] (c) circle (2pt)
        \p1 = (current path bounding box.south west),
        \p2 = (current path bounding box.north east)
  node at (current path bounding box) {% should be in the center of the current path
    {This is the intersection point\textCR of the two lines!}%

However, for circles this seems to generate a rectangle which fits into the circle not around it.

For multiple paths you can use a scope and track the bounding box of it using local bounding box. Then use the same measurement technique as above.

share|improve this answer
Thanks, your solutions works after adding \usetikzlibrary{calc} (TikZ creates a useful error message! Hurrah! ;-)). As i'm not a regular user of TikZ i will have to look up the scope thing tomorrow. – Josef May 19 '11 at 19:13
@Josef: Ups, yeah I forgot to mention the calc library. It should be also possible to use some path option to execute the code after the path. – Martin Scharrer May 19 '11 at 19:15

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.