如何自动适应标注节点(包括其指针提示)?

如何自动适应标注节点(包括其指针提示)?

我正在尝试“自动”适应标注节点(包括其指针),但我无法包含指针提示:

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{positioning, calc, shapes.callouts, fit}
\tikzset{%
    pics/postit/.style n args={3}{code={%
        \node[draw=red,rectangle callout,callout relative pointer={(#1,#2)}] (mynode) {#3};
        \node (pointertip) at ($(mynode)+(#1,#2)$) {};
        \node[draw=green, thick, inner sep=0pt, fit=(mynode)(pointertip)] {};
    }},
}

\begin{document}
\begin{tikzpicture}
    \pic {postit={1}{0}{How to}};
    \pic at (0,-1) {postit={-2}{0}{automatically}};
    \pic at (0,-2) {postit={0}{-1}{fit}};
    \pic at (0,-6) {postit={0}{2}{a callout}};
    \pic at (0,-7) {postit={-1}{-1}{node,}};
    \pic at (0,-9.5) {postit={1}{1}{its}};
    \pic at (0,-11) {postit={-1}{1}{pointer tip}};
    \pic at (0,-12) {postit={1}{-1}{included?}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

指针已有一个锚点,您可以使用

pics/postit/.style n args={3}{code={%
    \node[draw=red,rectangle callout,callout relative pointer={(#1,#2)}] (mynode) {#3};
    \node[draw=green, thick, inner sep=0pt, fit=(mynode)(mynode.pointer)] {};
}},

在此处输入图片描述

相关内容