如何旋转 TikZ 装饰(箭头)?

如何旋转 TikZ 装饰(箭头)?

虽然 TikZ 可以选择弯曲出现在边缘尖端的箭头(库bending),也可以选择将箭头放置在边缘中间(库decorations),但我无法将两者结合起来。在下面的代码中,我使用库decorations将箭头放置在循环中间附近,但箭头的方向是根据尖端曲线的切线确定的。是否可以弯曲箭头,甚至只是将其旋转一个硬编码的角度?

\pdfoutput=1
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
  \tikzset{->-/.style={decoration={markings, mark=at position #1 with {\arrow{stealth}}},postaction={decorate}}}
  \node[draw,circle] (n) {$n$};
  \draw [->-=.5] (n) to [distance=5ex, in=60, out=120, loop] ();
\end{tikzpicture}
\end{document}

带箭头的圆形字母上方有箭头:箭头与环尖端所在的点相切,而不是沿着环的曲率

答案1

在装饰时,\pgfdecoratedangle保存路径切线角度以调整变换。您可以使用该角度或任何与该量相偏移的硬编码值

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}
\tikzset{->-/.style={
  decoration={markings, mark=at position #1 with {%
    \arrow[rotate=-\pgfdecoratedangle]{stealth}% always point right
    }
  },
  postaction={decorate}
  }
}

  \node[draw,circle] (n) {$n$};
  \draw [->-=.2] (n) to [distance=5ex, in=60, out=120, loop] ();
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容