我对 Tikz 还很陌生。如何绘制没有矩形边界的圆角箭头和节点。我想画这样的东西:
答案1
绘制曲线路径是完全有可能的。有几种方法可以做到这一点:
您可以使用该to
指令:
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node (A) at (0,0) {A};
\node (B) at (0,-2in) {B};
\draw[arrows=->] (A) to[out=-45,in=45] (B);
\end{tikzpicture}
\end{document}
您可以使用controls
\begin{tikzpicture}
\node (A) at (0,0) {A};
\node (B) at (0,-2in) {B};
\draw[arrows=->] (A) .. controls (2,-0.5in) and (2,-1.5in) .. (B);
\end{tikzpicture}
以下内容开始类似于您发布的图像:
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{calc}
\def\myVpos{0}
\def\myVadj{1}
\def\myToneList{1/call/m1,
2/lock/l,
3/write/x,
4/unlock/l,
5/ret/m1,
11/call/m3,
12/lock/l,
13/read/x,
14/unlock/l,
15/ert/m3}
\def\myTtwoList{6/call/m2,
7/lock/l,
8/write/x,
9/ret/l,
10/ret/m2}
\begin{document}
\begin{tikzpicture}
%% T1 list
\foreach \x/\y/\z
[evaluate={\myVpos=\myVpos+\myVadj},
remember=\myVpos as \myVpos (initially 0)
]
in \myToneList
{
\node (t1_\x) at (0,-\myVpos) {{\ttfamily\y(t1,\z)}};
\node at ($(t1_\x)+(-1.5cm,0)$) {\x};
}
\xdef\myCurrentPos{t1_1}
\foreach \x/\y/\z in \myToneList
{
\edef\myTest{t1_\x}
\ifx\myCurrentPos\myTest\else\draw[arrows=->] (\myCurrentPos.south) to (t1_\x.north) ; \fi
\xdef\myCurrentPos{t1_\x}
}
%%\draw[arrows=->,dashed] (t1_4.east) to[out=-10,in=10] node[right] {?} (t1_12.east);
\draw[arrows=->,dashed]
(t1_4.east)
..
controls ($(t1_4)+(-10:3.5cm)$)
and
($(t1_12)+(10:5.5cm)$)
..
node[right,pos=0.65] {?}
(t1_12.east);
%% T2 list
\foreach \x/\y/\z
[evaluate={\myVpos=\myVpos+\myVadj},
remember=\myVpos as \myVpos (initially 0)
]
in \myTtwoList
{
\node (t2_\x) at (6,-\myVpos) {{\ttfamily\y(t2,\z)}};
\node at ($(t2_\x)+(1.5cm,0)$) {\x};
}
\xdef\myCurrentPos{t2_6}
\foreach \x/\y/\z in \myTtwoList
{
\edef\myTest{t2_\x}
\ifx\myCurrentPos\myTest\else\draw[arrows=->] (\myCurrentPos.south) to (t2_\x.north) ; \fi
\xdef\myCurrentPos{t2_\x}
}
%% across T1 and T2
\draw[arrows=->] (t1_4.north east) -- (t2_7.south west);
\draw[arrows=->] (t2_9.south west) -- (t1_12.north east);
\end{tikzpicture}
\end{document}