You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在LaTeX TikZ中为节点添加外部弯曲自指向箭头

TikZ实现节点外部自指向弯曲箭头

要实现从节点右上角出发、外部弯曲后回到左上角的自指向箭头,你需要替换原来的直线连接方式,改用TikZ的to路径配合弯曲参数。以下是修正后的完整代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
node distance=1.5cm and 1cm,
ar/.style={->,>=latex}, % 修正原代码转义错误的箭头样式
middle_node/.style={
  draw,
  text width=1.5cm,
  minimum height=0.75cm,
  align=center
  },
end_node/.style={
  draw,
  text width=1cm,
  minimum height=0.55cm,
  align=center
  }
]

  % 节点定义
  \node[end_node] (start) {\textbf{start}};
  \node[middle_node,right=of start] (first_step) {a};
  \node[middle_node,right=of first_step] (second_step) {b};
  \node[middle_node,right=of second_step] (third_step) {c}; 
  \node[end_node, right=of third_step] (stop) {\textbf{stop}};

  % 箭头绘制
  \draw[ar] (start) -- (first_step);
  % 自指向弯曲箭头:从右上角锚点出发,向上弯曲后回到左上角锚点
  \draw[ar] (first_step.north east) to[out=45, in=135, looseness=1.5] (first_step.north west);
  \draw[ar] (first_step) -- (second_step);
  \draw[ar] (second_step) -- (third_step);
  \draw[ar] (third_step) -- (stop);
\end{tikzpicture}
\end{document}

关键说明:

  • 用to[out=..., in=...]替代--直线连接,可自定义箭头的出发与进入方向:
    • out=45:箭头从右上角锚点出发时,指向右上45度方向
    • in=135:箭头进入左上角锚点时,从左上135度方向接入
    • looseness=1.5:调整弯曲幅度,数值越大箭头弯曲程度越高
  • 也可以用更简洁的bend left语法实现类似效果,比如:
    \draw[ar] (first_step.north east) to[bend left=60] (first_step.north west);
    
    修改60这个角度值就能调整弯曲弧度。

内容的提问来源于stack exchange,提问作者Daniel Miliński

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 01:31:06