自循环上的锚点(从该锚点画一条线)

自循环上的锚点(从该锚点画一条线)

我想注释图形的自循环,即从自循环开始写一条细线,然后转到一些文本。我的问题是我不知道如何访问与自循环“折返”点相对应的“锚点”。以下代码通过计算(通过尝试和错误)从自循环所连接的节点的偏移来手动执行此操作。但这并不好,因为我的节点的大小取决于节点内的文本(它可以在我的上下文中更改)。

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\node [circle, draw, font=\scriptsize] (n1) at (0,0) {$1$};
\path[->] (n1) edge [in=-10,out=20,loop] node {} (n1);
\path[draw=black!80,line width=0.6pt,dotted] ($(n1)+(0.7cm,0cm)$) to ($(n1)+(1.36cm,0cm)$) node[right] {\tiny annotation};
\end{tikzpicture}

\end{document}

答案1

coordinate在自我循环的某个位置使用。

在下面的代码中省略[pos=0.52]以使用默认值(midway,或者等效地pos=0.5)来获取曲线边缘的文字中点。我pos=0.52在此处的代码中对其进行了略微调整,以显示您可以根据需要进行的微调。

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\node [circle, draw, font=\scriptsize] (n1) at (0,0) {$1$};
\path[->] (n1) edge [in=-10,out=20,loop] coordinate[pos=0.52] (midp) (n1);
\path[draw=black!80,line width=0.6pt,dotted] (midp) -- +(1,0) node[right] {\tiny annotation};
\end{tikzpicture}

\end{document} 

在此处输入图片描述

答案2

您可以使用pin来执行此操作。但是,正如这里解释的那样,https://tex.stackexchange.com/a/219984/9335,我们必须先重置引脚边缘样式。

\documentclass[tikz,border=10]{standalone}
\tikzset{every pin edge/.append style={bend left=0,>={},->}}
\begin{document}
  \begin{tikzpicture}
    \node [circle, draw, font=\scriptsize] {$1$}
      edge [in=-10,out=20,loop,->] node[pos=0.52,pin=0:\tiny annotation]{} ();
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容