![如何在 Latex 中绘制此 DAG 依赖关系图](https://linux22.com/image/439513/%E5%A6%82%E4%BD%95%E5%9C%A8%20Latex%20%E4%B8%AD%E7%BB%98%E5%88%B6%E6%AD%A4%20DAG%20%E4%BE%9D%E8%B5%96%E5%85%B3%E7%B3%BB%E5%9B%BE.png)
我想知道如何在 Latex 中绘制类似的东西。请注意,边缘不是直线,就像我在许多 Tkz 示例中看到的那样。这是一个属性语法的示例,其中边缘表示属性值的流动。
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}[->,>=stealth',auto,node distance=2cm,
thick,main node/.style={draw}]
\node[main node, rectangle, align=center] (1) {$n_0.S$};
\node[main node, rectangle, align=center] (2) [below= of 1] {$n_1.I_1$};
\node[main node, rectangle, align=center] (3) [right =of 2, below= of 1] {$n_1.I_2$};
\node[main node, rectangle, align=center] (4) [right =of 3, below= of 1] {$n_1.S_1$};
\node[main node, rectangle, align=center] (5) [right =of 4, below= of 1] {$n_1.S_2$};
\node[main node, rectangle, align=center] (6) [below= of 1] {$n_2.I_1$};
\node[main node, rectangle, align=center] (7) [right =of 6, below= of 1] {$n_2.I_2$};
\node[main node, rectangle, align=center] (8) [right =of 7, below= of 1] {$n_2.S_1$};
\node[main node, rectangle, align=center] (9) [right =of 8, below= of 1] {$n_2.S_2$};
\draw (2.south) to (4.south);
\draw (4.south) to (5.south);
\draw (6.south) to (8.south);
\draw (7.south) to (9.south);
\draw (3.south) to (6.north);
\draw (5.south) to (7.north);
\draw (8.south) to (3.north);
\draw (9.south) to (2.north);
\draw (8.north) to (1.south);
\end{tikzpicture}
\end{document}
答案1
这是一个例子。我使用手动定位框(它们在原始图片中以不同的方式接触,因此我认为使用positioning
不是正确的工具)。我添加了一些可能的箭头来展示这个想法,您的 MWE 连接与上图不符。
我建议使用更明确的节点名称(如I1left
,I2left
等等),甚至可以通过一些\foreach
循环简化图表,但我只是在这里做了最少的工作来展示这个想法。
\documentclass[border=2.78mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta}%arrows is deprecated
\begin{document}
\begin{tikzpicture}[->,>=Stealth,auto,
thick,main node/.style={draw, rectangle, align=center, text width=1cm}]
\node[main node, ] (1) at (0,4) {$n_0.S$};
% stack left
\node[main node, ] (2) at (-6,0) {$n_1.I_1$};
\node[main node, anchor=north west] (3) at(2.north east) {$n_1.I_2$};
\node[main node, anchor=south west] (4) at(3.north east) {$n_1.S_1$};
\node[main node, anchor=north west] (5) at(4.north east) {$n_1.S_2$};
% stack right
\node[main node, ] (6) at (2,0) {$n_1.I_1$};
\node[main node, anchor=north west] (7) at(6.north east) {$n_1.I_2$};
\node[main node, anchor=south west] (8) at(7.north east) {$n_1.S_1$};
\node[main node, anchor=north west] (9) at(8.north east) {$n_1.S_2$};
\draw (2.south) to[out=-30, in=-120, looseness=1.2] (4.south);
\draw (3.south) to[out=-30, in=-120, looseness=1.2] (5.south);
\draw (6.south) to[out=-30, in=-120, looseness=1.2] (8.south);
\draw (7.south) to[out=-30, in=-120, looseness=1.2] (9.south);
\draw (3.north) to[out=30, in=120, looseness=1.2] (6.north);
\draw (8.north) to[out=90, in=-90] (1.south);
% the control points are relative to the star point here
\draw[red] (8.north) .. controls +(-1,1) and +(-5,2) .. (3.north);
\end{tikzpicture}
\end{document}