3

Consider:

\documentclass[12pt, a4paper]{report}
    \begin{document}
    \usepackage{tikz}
    \usetikzlibrary{arrows.meta, positioning, quotes}
\begin{figure} \centering
  \begin{tikzpicture}[
node distance = 33mm and 33mm,
     N/.style = {draw, minimum size=12mm, inner sep=0pt},
            > = {Stealth[scale=0.6]},
 every edge/.append style = {draw, ->},
every edge quotes/.append style = {font=\small\linespread{0.75}\selectfont,
                                   inner sep=5pt, sloped}
                        ]
\node [N] (A) {$S$};
\node [N, right=of A] (B) {$A$};
\node [N,below=of B] (C) {$I$};
\node [N,left=of C] (D) {$R$};
%
\draw [<-] (A) -- ++(-1,0) node[left] {$b\left(1-\nu\right)$};
\draw [<-] (D) -- ++(-1,0) node[left] {$b\nu$};
\draw [->] (A) -- ++(0,1) node[above] {$\mu S$};
\draw [->] (B) -- ++(0,1) node[above] {$\mu A$};
\draw [->] ([xshift=-3.5mm] C.south) -- ++(0,-0.4) node[below] {$\alpha I$};
\draw [->] ([xshift=+3.5mm] C.south) -- ++(0,-0.4) node[below] {$\mu I$};
\draw [->] (D) -- ++(0,-1) node[below] {$\mu R$};
\draw[->] (B)--(D) node[midway,sloped,above]{$\gamma_A$};
%
\end{tikzpicture}
\setlength{\textfloatsep}{10pt plus 1.0pt minus 2.0pt}
\caption{Flow diagram for the SAIRS model.}
\end{figure}
  \end{document}

What I'd like is:

enter image description here

I'd like it to be similar to this format./layout using tikzpicture:

\documentclass[12pt, a4paper]{report}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, quotes}    

\begin{document}
\begin{figure} \centering
\begin{tikzpicture}[
node distance = 11mm and 33mm,
     N/.style = {draw, minimum size=12mm, inner sep=0pt},
            > = {Stealth[scale=0.6]},
every edge/.append style = {draw, ->},
every edge quotes/.append style = {font=\small\linespread{0.75}\selectfont,
                                       inner sep=5pt, sloped}
                            ]
\node [N] (A) {$S$};
\node [N,above right=of A] (B) {$I_1$};
\node [N,below right=of A] (C) {$I_2$};
\node [N,above right=of C] (D) {$J$};
\node [N,right=of D] (E)  {$A$};
%
\draw [<-] (A) -- ++(-1,0) node[left] {$\mu$};
\draw [->] (A) -- ++(0,-1) node[below] {$\nu S$};
\draw [->] ([xshift=3.75mm] B.south) -- ++(0,-0.4) node[below] {$\nu I_1$};
\draw [->] (C) -- ++(0,-1) node[below] {$\nu I_2$};
\draw [->] (D) -- ++(0,-1) node[below] {$\nu J$};
\draw [->] ([xshift=-3.5mm] E.south) -- ++(0,-0.4) node[below] {$\alpha A$};
    \draw [->] ([xshift=+3.5mm] E.south) -- ++(0,-0.4) node[below] {$\nu A$};
    %
\draw   ([yshift=+1mm] A.east)
                edge [ultra thick, draw=gray,"\slash\slash\slash" anchor=center,
                      "$\begin{gathered}
                            p\beta_1 S I_2\\
                            q\beta_2 S J\\
                            r\beta_3 S A
                        \end{gathered}$" ] (B.west)
            ([yshift=-1mm] A.east)
                edge [ultra thick, draw=gray,"\slash\slash\slash" anchor=center,
                      "$\begin{gathered}
                            (1-p)\beta_2 S I_2\\
                            (1-q)\beta_2 S J\\
                            (1-r)\beta_3 S A
                        \end{gathered}$" '] (C.west)
           (B) edge [rotate=90,"$\epsilon I_1$"] (C)
            (D.west) edge ["$\xi_1 J$"  ] ( B.east)
            ( C.east) edge ["$p_1 I_2$"  ] (D.west)
            ([yshift=-2mm] D.west) edge ["$\xi_2 J$" '] ([yshift=-2mm] C.east)
        (D) edge ["$p_2 J$"] (E);
\end{tikzpicture}
\end{figure}
\end{document}

EDIT:

Why doesn't this code work:

\documentclass[12pt, a4paper]{report}
        \begin{document}
        \usepackage{tikz}
        \usetikzlibrary{arrows.meta, positioning, quotes}
    \begin{figure} \centering
      \begin{tikzpicture}[
    node distance = 33mm and 33mm,
         N/.style = {draw, minimum size=12mm, inner sep=0pt},
                > = {Stealth[scale=0.6]},
     every edge/.append style = {draw, ->},
    every edge quotes/.append style = {font=\small\linespread{0.75}\selectfont,
                                       inner sep=5pt, sloped}
                            ]
    \node [N] (A) {$S$};
    \node [N, right=of A] (B) {$A$};
    \node [N,below=of B] (C) {$I$};
    \node [N,left=of C] (D) {$R$};
    %
    \draw [<-] (A) -- ++(-1,0) node[left] {$b\left(1-\nu\right)$};
    \draw [<-] (D) -- ++(-1,0) node[left] {$b\nu$};
    \draw [->] (A) -- ++(0,1) node[above] {$\mu S$};
    \draw [->] (B) -- ++(0,1) node[above] {$\mu A$};
    \draw [->] ([xshift=-3.5mm] C.south) -- ++(0,-0.4) node[below] {$\alpha I$};
    \draw [->] ([xshift=+3.5mm] C.south) -- ++(0,-0.4) node[below] {$\mu I$};
    \draw [->] (D) -- ++(0,-1) node[below] {$\mu R$};
    %
    \draw
     (A) edge [rotate=90,"$\rho S$"] (D)
     (A) edge ["$(\beta_A A+\beta_I I)S$"]
     (B) edge["$\sigma A$"](C)
     ([yshift=-2mm] B.west) edge ["$\gamma_A A$" '] ([yshift=-2mm] D.east)
     (C) edge["$\gamma_I$"](D)
     (C) edge[bend left,"$\eta$"](D)
     (D) edge ["$\xi R$"] (A)
    \end{tikzpicture}
    \setlength{\textfloatsep}{10pt plus 1.0pt minus 2.0pt}
    \caption{Flow diagram for the SAIRS model.}
    \end{figure}
\end{document}
10
  • It's recommended to include the image output of your current code. Easier for us to look at.
    – user202729
    Jun 16 at 12:19
  • Creating double arrow / parallel arrows with tikz - TeX - LaTeX Stack Exchange should work for you? Anything else you need help with?
    – user202729
    Jun 16 at 12:21
  • Take a look at the Automata Drawing Library wich is easy to use.
    – projetmbc
    Jun 16 at 13:31
  • 1
    I took liberty and make your second MWE compilable. BTW, you got nice answer. I would use it. About consistency: for example that you start to saw wood by hand saw, but then you get opportunity to get motorized chain saw ... would you still further saw by hand due to consistency?
    – Zarko
    Jun 16 at 14:22
  • @Zarko I understand your analogy, however I like the aesthetics of the solution you provided in the other flow diagram(small arrow heads, square nodes, spaced out so diagram doesn't look squashed) :)
    – Math
    Jun 16 at 14:26

2 Answers 2

6

A wee bit modified nice @Luis Turcio answer (+1):

  • a bit shorter code due to use a bit different (shorter) syntax
  • with square shape for main nodes (as OP wish to have)
  • bigger distances between nodes
\documentclass[margin=3mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz-cd}
\tikzcdset{arrow style=tikz,            % <--- new
           diagrams={>=Straight Barb}
           }

\begin{document}
    \begin{tikzcd}[%nodes in empty cells,
                   cells={nodes={draw,anchor=center}},
                   sep=huge]
|[draw=none]|
   & |[draw=none]|\mu 
        & |[draw=none]|\mu       \\
|[draw=none]|\rar["b(1-\nu)"] 
    & S \uar
        \rar["(B_A H B_I I)"]
        \dar[shift right,"\rho"'] 
        & A \uar
            \dar["\delta"]
            \dlar["\delta_a" ']  \\
|[draw=none]|\rar["b\nu"] 
    & R \dar
        \uar[shift right,"\varepsilon" '] 
        & I \dar
            \lar[shift right,"\delta_I" ']
            \lar[shift left,bend left,"\tau"] \\
|[draw=none]|
    & |[draw=none]|\mu 
        & |[draw=none]|\mu+\alpha
    \end{tikzcd}
\end{document}

enter image description here

Regarding your MWE in edited part of question:

  • package had to be loaded before \begin{document}
  • second command for drawing arrows is not terminated by \\
  • second line in drawing arrows has not defined target coordinate (consequently edges have wrong positions)

Correcting this, your code can be compiled without any problem. But result is probably not what you are after:

enter image description here

It seems that you make mistake at selecting arrows coordinates.

Addendum: I assume, that your code should be something like this:

\documentclass[12pt, a4paper]{report}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, quotes}

\begin{document}
    \begin{figure} \centering
    \begin{tikzpicture}[
node distance = 33mm and 33mm,
     N/.style = {draw, minimum size=12mm, inner sep=0pt},
            > = Stealth,
       every edge/.append style = {draw, ->},
every edge quotes/.append style = {font=\small\linespread{0.75}\selectfont,
                                   inner sep=5pt}
                            ]
\node [N]               (A) {$S$};
\node [N,right=of A]    (B) {$A$};
\node [N,below=of B]    (C) {$I$};
\node [N, left=of C]    (D) {$R$};
    %
\draw [<-] (A) -- ++(-1,0) node[left] {$b\left(1-\nu\right)$};
\draw [<-] (D) -- ++(-1,0) node[left] {$b\nu$};
\draw [->] (A) -- ++( 0,1) node[above] {$\mu S$};
\draw [->] (B) -- ++( 0,1) node[above] {$\mu A$};
\draw [->] ([xshift=-3.5mm] C.south) -- ++(0,-0.4) node[below] {$\alpha I$};
\draw [->] ([xshift=+3.5mm] C.south) -- ++(0,-0.4) node[below] {$\mu I$};
\draw [->] (D) -- ++(0,-1) node[below] {$\mu R$};
    %
\draw
     (A.260) edge ["$\rho S$" '] (D.100)
     (A) edge ["$(\beta_A A+\beta_I I)S$"]  (B)
     (B) edge ["$\delta$" '] (C)
     (B) edge["$\sigma A$"] (D)
     (C) edge["$\gamma_I$"](D)
     (C) edge[bend left,"$\eta$"](D)
     (D.80) edge ["$\xi R$" '] (A.280)
     ;
    \end{tikzpicture}
%    \setlength{\textfloatsep}{10pt plus 1.0pt minus 2.0pt} % is really needed?
    \caption{Flow diagram for the SAIRS model.}
    \end{figure}
\end{document}

which gives:

enter image description here

7
  • This is perfect! Thank you :) The code isnt compiling on my computer with the error ! Missing \endcsname inserted. <to be read again> \begingroup l.2965 (A.260) edge ["$\rho S$" '] (D.100) ?
    – Math
    Jun 20 at 10:52
  • do you know any fixes?
    – Math
    Jun 27 at 13:10
  • @Math, my MWE compile without any error, warnings or bad boxes. So I haven't any clue, what is cause of your error. It is not in MWE as it is. You change something or you have an ancient LaTeX installation. Try to upgrade it.
    – Zarko
    Jun 27 at 14:33
  • ok I tried on a fresh file and it works.. so do you know why it doesn't it work on my actual document?
    – Math
    Jun 27 at 14:36
  • @Math, how should i know? I didn't see it. I can't test it. I don't know how you use proposed solution. Apparently you have some error in it which you eliminate by fresh installation. Sorry, I haven't crystal ball to see what is going on in your place ;-)
    – Zarko
    Jun 27 at 14:43
9

This kind of diagrams are easy with tikz-cd:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[cells={nodes={draw=black,circle,anchor=center}},column sep=large]
& |[draw=none]|\mu & |[draw=none]|\mu\\
|[draw=none]|{}\ar{r}{b(1-\nu)} & S\ar{u}\ar{r}{(B_A H B_I I)}\ar[shift right]{d}[swap]{\rho} & A\ar{u}\ar{d}{\delta}\ar{dl}[swap]{\delta_a}\\
|[draw=none]|{}\ar{r}{b\nu} & R\ar{d}\ar[shift right]{u}[swap]{\varepsilon} & I\ar[shorten > = -1.9ex]{d}\ar[shift right]{l}[swap]{\delta_I}\ar[shift left,bend left=20]{l}{\tau}\\
& |[draw=none]|\mu & |[draw=none]|\mu+\alpha
\end{tikzcd}
\end{document}

enter image description here

3
  • Although this is not like the format I want it is a nice answer so +1 :)
    – Math
    Jun 16 at 13:09
  • Whats wrong with the format?
    – Ingmar
    Jun 16 at 13:59
  • What I meant is, I provided a similar but different flow diagram for a different section in my document so I'd like to format of the diagrams to be consistent.
    – Math
    Jun 16 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.