我需要创建一个像 Uml 活动图这样的自动机,我用过这个关联但我不明白。
我尝试使用以下代码来实现这一点:
\begin{tikzpicture}[>=stealth,every node/.style={shape=rectangle,draw,rounded corners},]
% create the nodes
\node (c0)[shape=circle, fill=black] {};
\node (c1) [right =of c0]{label 1};
\node (c2) [below =of c1]{label 2};
\node (c3) [below =of c2]{label 3};
% connect the nodes
\draw[->] (c0.north) to[out=90,in=90] (c1.north);
%\draw[->] (c1.south) to[out=180,in=180] (c0.south);
\draw[->] (c1.west) to[out=180,in=180] (c2.west);
\draw[->] (c2) to[out=180,in=180] (c3);
\draw[->] (c3.east) to[out=180,in=180] (c2.east);
\draw[->] (c3.east) to[out=180,in=180] (c1.east);
\end{tikzpicture}
我也误解了如何使用此命令to [out = X in = Y]
来修复箭头的方向
不幸的是,我得到了这个数字
答案1
我猜你喜欢获得
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[>=stealth,
every node/.style={shape=rectangle, draw, rounded corners}
]
% create the nodes
\node (c0) [shape=circle, fill=black] {};
\node (c1) [right = of c0] {label 1};
\node (c2) [below = of c1] {label 2};
\node (c3) [below = of c2] {label 3};
% connect the nodes
\draw[->] (c0) to[out= 75,in=105] (c1);
\draw[->] (c1) to[out=255,in=285] (c0);
\draw[->] (c1) to[out=185,in=175] (c2);
\draw[->] (c2) to[out=185,in=175] (c3);
\draw[->] (c3) to[out= 10,in=350] (c2);
\draw[->] (c3) to[out= 5,in=355] (c1);
\end{tikzpicture}
\end{document}
正如我在评论中提到的那样,out=X, in=Y
(参见逗号,它分隔了角度的出入)意味着线out
从角度处的坐标(节点)出发X
,到达角度处的坐标Y
。角度是从节点中心测量的。观察 MWE 中所选角度与上方 MWE 之间的差异:箭头和节点的右侧以接近 10 度的角度“离开”节点,并以度“到达” 350
。