2

I'm trying to graph a SIS epidemic model with Tikzpicture like the one in this page http://pythonhosted.org/epigrass/intromodels.html . My problem is I'm not able to make the arrow from the I compartment to S compartment.

Moreover I would like to add other arrows that go out of the box for considering the demography (For this I have no idea about how to proceed).

I print here my wrong code:

\begin{tikzpicture}[node distance=6cm,auto,>=latex',every node/.append style={align=center}]
    \node [int] (a)              {$S$};
    \node [int]             (c) [right of=a] {$I$};
    \path[->, auto=false] (a) edge node {$\beta I$ \\[.2em]} (c)
                          (c) edge node {$\gamma$       \\[.2em] } (e) ;
\end{tikzpicture}
andreasvr
  • 155

1 Answers1

5

Something like this?

enter image description here

I had to define int style and include arrows library for latex'. I've also replaced right of with the new syntax (positioning library) righ= of (see: Difference between "right of=" and "right=of" in PGF/TikZ)

For arrows going out of the box I've used a coordinate node although some other solutions are also possible.

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{arrows,positioning}

\begin{document}

\begin{tikzpicture}[node distance=1cm,auto,>=latex',every node/.append style={align=center},int/.style={draw, minimum size=1cm}]
    \node [int] (S)             {$S$};
    \node [int, right=of S] (I) {$I$};
    \coordinate[right=of I] (out);
    \path[->, auto=false] (S) edge node {$\beta I$ \\[.2em]} (I)
                          (I) edge node {$\gamma$       \\[.2em] } (out) edge  [out=-120, in=-60] node[below] {$\delta$} (S);
\end{tikzpicture}
\end{document}

Update:

Torbjørn T. proposed some more improvements to your code:

Replacing syntax node {$\beta I$ \\[.2em]} with simply node[above] {$\beta I$} which is the TiKZ way for placing an edge label above the arrow. In this case, as you already included auto option, there's no need for [above] because edge labels are automatically placed following arrow direction. You stopped this automatism with auto=false.

Using new arrows.meta library instead of deprecated (although still supported) arrows. As an example, latex' style has been replaced by Latex

The new code is:

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{arrows.meta,positioning}

\begin{document}

\begin{tikzpicture}[node distance=1cm, auto,
    >=Latex, 
    every node/.append style={align=center},
    int/.style={draw, minimum size=1cm}]

   \node [int] (S)             {$S$};
   \node [int, right=of S] (I) {$I$};
   \coordinate[right=of I] (out);
   \path[->] (S) edge node {$\beta I$} (I)
             (I) edge node {$\gamma$} (out) 
                 edge[out=-120, in=-60] node {$\delta$} (S);
\end{tikzpicture}
\end{document}
Ignasi
  • 136,588
  • Wouldn't it be better with e.g. node [above] {$\beta I$} instead of adding a linebreak? (I know it came from the OPs code.) And not that I consider it a big deal, but the manual for v3 states that the arrows library is considered deprecated in favor of arrows.meta, as you probably know. – Torbjørn T. Dec 11 '15 at 07:48
  • @TorbjørnT. You're right. I've not seen it. I've included your suggestions. Thank you for pointing them. – Ignasi Dec 11 '15 at 08:16