2

I am trying to create a SIRS (Susceptible-Infectious-Recovered-Susceptible) diagram that looks like this: enter image description here

I am almost there; I have all but the top arrow going from Recovered to Susceptible. Here is my current code:

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{positioning, arrows.meta}

\begin{document}

\begin{tikzpicture}[ node distance=2.5cm, arrow/.style={->, >=Stealth, thick}, box/.style={draw, rectangle, rounded corners, minimum width=2cm, minimum height=1cm, align=center} ]

% Nodes \node[box] (S) {Susceptible}; \node[box, right=of S] (I) {Infectious}; \node[box, right=of I] (R) {Recovered};

% Arrows \draw[arrow] (S) -- node[above]{$\beta$} (I); \draw[arrow] (I) -- node[above]{$\gamma$} (R);

\end{tikzpicture}

\end{document}

And here is what my code produces: enter image description here

I am having trouble with drawing the arrow from Recovered to Susceptible. How do I draw an arrow so that it goes over the boxes without overlapping them? Any help would be greatly appreciated.

Leonidas
  • 165

1 Answers1

3

Here was my original naive attempt:

\node (A) [above=0.5cm of I] {$\delta$};
\draw[arrow] (R.north) |- (A.south) -| (S.north); 

User Sandy G gives a better option which is to use a technique which was surprisingly difficult to research (turns out googling --++ is tough); I found this OLD (11yr) post which talks about it: TiKz dash dash plus plus which led me to the TikZ manual section 13.4 Relative and Incremental Coordinates

We can specify a relative coordinate using ++ before a new path coordinate to make it relative to the coordinate which came before it in the path. From the manual:

You can prefix coordinates by ++ to make them “relative”. A coordinate such as ++(1cm,0pt) means “1cm to the right of the previous position, making this the new current position”. Relative coordinates are often useful in “local” contexts:

This makes it as easy as:

\draw[arrow] (R.north) -- ++(0,0.5) -| (S.north) node[above, pos=0.25] {$\delta$};

This will draw a node from the north of node R, up 0.5, then connect to the north of S but take a sharp turn to get there (specified by -|). A node is placed 0.25 above the path (which happens to be symmetrical) and filled with $\delta$.

MWE

Both answers will give roughly the same image, but I thought you'd enjoy seeing multiple perspectives.

MWE:

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{positioning, arrows.meta}

\begin{document}

\begin{tikzpicture}[ node distance=2.5cm, arrow/.style={->, >=Stealth, thick}, box/.style={draw, rectangle, rounded corners, minimum width=2cm, minimum height=1cm, align=center} ]

% Nodes
\node[box] (S) {Susceptible};
\node[box, right=of S] (I) {Infectious};
\node[box, right=of I] (R) {Recovered};

% Arrows
\draw[arrow] (S) -- node[above]{$\beta$} (I);
\draw[arrow] (I) -- node[above]{$\gamma$} (R);

% My Naive Attempt
% \node (A) [above=0.5cm of I] {$\delta$};
% \draw[arrow] (R.north) |- (A.south) -| (S.north);

% Sandy G's code
\draw[arrow] (R.north) -- ++(0,.5) -| (S.north) node[above, pos=0.25] {$\delta$};

\end{tikzpicture}

\end{document}

Altissimo
  • 146