今天在pdfcomment
( \pdftooltip
) 中添加了对工具提示的支持后,我想制作一个TikZ
带有工具提示注释的示例。\pdftooltip
注释元素内设置了一个框来测量大小,这对图形的某些部分不起作用。以下示例中TikZ
有解决方法(手动框或):\textbullet
\documentclass{article}
\usepackage{tikz}
\usepackage{pdfcomment}[2011/05/19]
% http://svn.berlios.de/viewvc/pdfcomment/trunk/dev/tex/latex/pdfcomment/pdfcomment.sty?revision=11
\begin{document}
\begin{tikzpicture}[scale=1.5]
% 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!}}
\end{tikzpicture}
\end{document}
有没有办法让TikZ
图形的一部分放入盒子中时产生尺寸?
答案1
我会将工具提示作为路径的一部分。然后,您可以使用访问路径边界框current path bounding box
并测量其尺寸。
\fill[red] (c) circle (2pt)
let
\p1 = (current path bounding box.south west),
\p2 = (current path bounding box.north east)
in
node at (current path bounding box) {% should be in the center of the current path
\pdftooltip{\rule{\dimexpr\x2-\x1\relax}{0pt}\rule{0pt}{\dimexpr\y2-\y1\relax}}%
{This is the intersection point\textCR of the two lines!}%
};
然而,对于圆形来说,这似乎会生成一个适合圆形而不是围绕圆形的矩形。
对于多条路径,您可以使用示波器并使用跟踪其边界框local bounding box
。然后使用与上述相同的测量技术。