我一直在尝试在 TikZ 布局中表示旋转。在命名或为节点添加别名方面,我已经用尽了大多数选项,但没有任何运气。实际上,我试图理想地引用三个节点 {A、B、C} 的坐标,然后在这三个节点之间绘制一条从 A 开始到 C 的半圆形路径。下面是我的树块和相关包:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,arrows.meta}
\usegdlibrary{trees}
\tikzset{rn/.style = {draw=red, circle, dashed, inner sep=2pt, minimum size = 15pt, align=center}}
\tikzset{bn/.style = {draw, circle, double, inner sep=2pt, minimum size = 15pt, align=center}}
\tikzset{ebn/.style = {draw, circle, double, inner sep=1pt, minimum size = 5pt, align=center}}
\begin{document}
\begin{tikzpicture} [binary tree layout, scale=1.25]
\node [bn] {30}
child{node [bn] {20}
child{node [ebn] {}}
child{node [ebn] {}}
}
child{node [rn] {40}
child{node [bn] {38}
child{node (a) [rn] {35}
child{node [thick, rn] {31}}
child{node [ebn] {}}}
child{node (b) [ebn] {}}
}
child{node [rn] {45}
child{node [ebn] {}}
child{node [ebn] {}}}
};
\draw [->] (a.east) arc (b.west);
\end{tikzpicture}
\end{document}
答案1
您非常接近,但是,arc
这不是正确的命令。您想在三角形 {a,b,c} 内绘制一条曲线路径,您应该使用该controls
操作。您还加载了各种库,但这些库都不是绘图所必需的。
\documentclass{standalone}
\usepackage{tikz}
\tikzset{
rn/.style = {draw=red, circle, dashed, inner sep=2pt, minimum size = 15pt, align=center},
bn/.style = {draw, circle, double, inner sep=2pt, minimum size = 15pt, align=center},
ebn/.style = {draw, circle, double, inner sep=1pt, minimum size = 5pt, align=center},
}
\begin{document}
\begin{tikzpicture}[
scale=1.25,
level/.style={
sibling distance=3cm/#1,
level distance=1cm,
},
]
\node [bn] {30}
child{node [bn] {20}
child{node [ebn] {}}
child{node [ebn] {}}
}
child{node [rn] {40}
child{node (c) [bn] {38}
child{node (a) [rn] {35}
child{node [thick, rn] {31}}
child{node [ebn] {}}}
child{node (b) [ebn] {}}
}
child{node [rn] {45}
child{node [ebn] {}}
child{node [ebn] {}}}
};
\draw [ultra thick,red,shorten <=2pt,shorten >=2pt]
(a) .. controls ([yshift=-.2cm]c) .. (b);
\end{tikzpicture}
\end{document}