2

I am wondering how to draw something like this in Latex. Notice the edges are not straight lines as I see in many Tkz examples. This is an example of attribute grammar where edges indicate the flow of attribute values.

enter image description here

\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}

enter image description here

Node.JS
  • 685

1 Answers1

4

This is an example. I am using manual positioning of the boxes (they touch in different ways in your original picture, so I do not think that using positioning is the right tool here). I added a few possible arrows to show the idea, your MWE connections did not correspond to the diagram above.

I would suggest using more explicit node names (like I1left, I2left etc.) that could even led to streamlining the diagram with some \foreach loop, but I just did the minimum work here to show the idea.

\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}

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125