3

How would I draw the following diagram?

enter image description here

Please can you put $\epsilon$ on the left rather than the right.

The best I can do is:

\begin{tikzpicture}[node distance=2cm, on grid]
  \tikzset{
    mynode/.style = {circle,draw,minimum width=8mm,inner sep=0pt},
    > = {Stealth[scale=1.5]}
  }
  \node [mynode] (A1) {S};
  \node [mynode,right=of A1] (B1) {I_1};
  \node [mynode,right=of B1] (C1) {I_2};
  \node [mynode,right=of C1] (D1) {J};
  \draw [<-] (A1) -- ++(-1,0) node[left] {$\mu$};
  \draw [->] (A1) -- node[above] {$\beta$} (B1);
  \draw [->] (B1) -- node[above] {$\sigma$} (C1);
  \draw [->] (C1) -- node[above] {$\gamma$} (D1);
  \draw [->] (A1) -- ++(0,-1) node[below] {$\nu$};
  \draw [->] (B1) -- ++(0,-1) node[below] {$\nu$};
  \draw [->] (C1) -- ++(0,-1) node[below] {$\nu$};
  \draw [->] (D1) -- ++(0,-1) node[below] {$\nu$};
  \draw [->] (D1) to[out=135,in=45] node[above] {$\xi$} (A1);
\end{tikzpicture}

This is what I'm looking for:

\documentclass[border=3mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}

\begin{document} \begin{tikzpicture}[ node distance = 11mm and 33mm, N/.style = {draw, minimum size=12mm, inner sep=0pt}, > = {Stealth[scale=0.8]}, every edge/.append style = {draw, ->}, every edge quotes/.append style = {font=\small\linespread{0.63}\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=3mm] 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] {$\nu \alpha$}; \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 I_1\ q\beta_2 JS\ r\beta_3 AS \end{gathered}$"] (B.west) ([yshift=-1mm] A.east) edge [ultra thick, draw=gray,"\slash\slash\slash" anchor=center, "$\begin{gathered} (1-p)\beta_2 I_1\ (1-q)\beta_2 JS\ (1-r)\beta_3 AS \end{gathered}$" '] (C.west) (B) edge ["$\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{document}

How do I flip the $\epsilon I_1$ so it reads left to right rather than on the side?

Display Name
  • 46,933
Math
  • 765
  • (i) make more clear sketch (ii) what you try so far? With use of the tikz package this should not be so big deal ... – Zarko Nov 18 '21 at 14:47
  • @Zarko I don't know how to make it clearer? – Math Nov 18 '21 at 14:49
  • Sorry, bur I cant read what you write on your sketch. But, more important is: show us what you try so far. BTW, this site is not intended for service: we-do-your task-instead-of-you. So. your questions seems to be closed soon. – Zarko Nov 18 '21 at 14:52
  • @Zarko i added something but it is way off.. and I would like square boxes – Math Nov 18 '21 at 15:34

2 Answers2

5

Well, your MWE is not very close to what you like to have. So, since you are novice to site as well to LaTeX/TikZ, the following MWE can serve as starting point to desired solution:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}

\begin{document} \begin{tikzpicture}[ node distance = 11mm and 22mm, N/.style = {draw, minimum size=12mm, inner sep=0pt}, > = {Stealth[scale=0.8]}, every edge/.append style = {draw, ->, 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] {$\mu_s$}; \draw [->] ([xshift=3mm] B.south) -- ++(0,-0.4) node[below] {$\mu I_1$}; \draw [->] (C) -- ++(0,-1) node[below] {$\mu I_2$}; \draw [->] (D) -- ++(0,-1) node[below] {$\mu I$}; \draw [->] ([xshift=-3mm] E.south) -- ++(0,-0.4) node[below] {$\mu I$}; \draw [->] ([xshift=+3mm] E.south) -- ++(0,-0.4) node[below] {$\mu I$}; % \draw ([yshift=+1mm] A.east) edge [ultra thick, draw=gray,"\slash\slash\slash" anchor=center, "${x,y,z}$" sloped] (B.west) ([yshift=-1mm] A.east) edge [ultra thick, draw=gray,"\slash\slash\slash" anchor=center, "${x',y',z'}$" sloped] (C.west) (B) edge ["$\sigma$"] (C) (B.east) edge ["$???$" ] ([yshift=+1mm] D.west) ( C.east) edge ["$???$" ] (D.west) ([yshift=-2mm] D.west) edge ["$???$" '] ([yshift=-2mm] C.east) (D) edge ["$???$"] (E); \end{tikzpicture} \end{document}

enter image description here

Addendum Still as starting point ... I still don't know, what are your edge labels. Anyway, from you comment I guess that from node S to nodes I_1 and I_2 are as shows the following image:

enter image description here

For this I made in the first MWE the following changes:

  • load package amsmath
  • increase distances between nodes
  • very long edge labels write in three lines by use of the gathered environment
\documentclass[border=3mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}

\begin{document} \begin{tikzpicture}[ node distance = 11mm and 33mm, N/.style = {draw, minimum size=12mm, inner sep=0pt}, > = {Stealth[scale=0.8]}, every edge/.append style = {draw, ->}, every edge quotes/.append style = {font=\small\linespread{0.63}\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] {$\mu_s$}; \draw [->] ([xshift=3mm] B.south) -- ++(0,-0.4) node[below] {$\mu I_1$}; \draw [->] (C) -- ++(0,-1) node[below] {$\mu I_2$}; \draw [->] (D) -- ++(0,-1) node[below] {$\mu I$}; \draw [->] ([xshift=-3mm] E.south) -- ++(0,-0.4) node[below] {$\mu I$}; \draw [->] ([xshift=+3mm] E.south) -- ++(0,-0.4) node[below] {$\mu I$}; % \draw ([yshift=+1mm] A.east) edge [ultra thick, draw=gray,"\slash\slash\slash" anchor=center, "$\begin{gathered} p\beta_1 I_1\ q\beta_2 JS\ r\beta_3 AS \end{gathered}$"] (B.west) ([yshift=-1mm] A.east) edge [ultra thick, draw=gray,"\slash\slash\slash" anchor=center, "$\begin{gathered} (1-p)\beta_2 I_1\ (1-q)\beta_2 JS\ (1-r)\beta_3 AS \end{gathered}$" '] (C.west) (B) edge ["$\sigma$"] (C) (B.east) edge ["$???$" ] ([yshift=+1mm] D.west) ( C.east) edge ["$???$" ] (D.west) ([yshift=-2mm] D.west) edge ["$???$" '] ([yshift=-2mm] C.east) (D) edge ["$???$"] (E); \end{tikzpicture} \end{document}

If you more prefer three lines between nodes S and I_1, I_2, please consider other answer.

Zarko
  • 296,517
  • That's a much better solution for the three parallel arrows! – Jasper Habicht Nov 18 '21 at 21:20
  • @JasperHabicht, thank you very much :-). Used notation is standardized in some electrical engineering fields (electrical power grid schemes, for example). I just borrow from them :-) – Zarko Nov 18 '21 at 21:27
  • @Zarko Thank you for your solution. The triple arrows from node $S$ to node $I_1$ should actually read $p \beta_1 I_2 S$, $q \beta_2 J S$ and $ r \beta_3 A S$. Similarly triple arrows from node $S$ to node $I_2$ should read $(1-p) \beta_1 I_2 S$, $(1-q) \beta_2 J S$ and $(1- r) \beta_3 A S$. I just simplified it down to x,y,z to make it more readable. – Math Nov 22 '21 at 11:48
  • @Zarko Following from my above comment, I don't think everything will "fit" using this notation so could you also amend the diagram for the triple arrows from the information above? I think the triple separate arrows method will be better. – Math Nov 22 '21 at 11:55
  • @Math, how to draw three arrows you can see in another answer. If drawing three is better is mater of taste. – Zarko Nov 22 '21 at 12:13
  • @Zarko I want the ideal diagram. Your solution is really nice however my labelling's are quite long so I don't know if it'll all fit which is why I suggested to edit yours. Or could you make a separate edit to show both? – Math Nov 22 '21 at 12:22
  • Dear @Math, in the first place you should provide better, readable sketch. (you can still do this, just small exercise of technical drawing with nice writing). I must confess, that I'm still not able to figured out, what are your edge labels. If they are to long, write it in three lines. See addendum in my answer (will appear ASAP). – Zarko Nov 22 '21 at 12:27
  • @Zarko I have added a better picture. Please have a look :) could you also stretch the image horizontally but squash it so it looks neater. – Math Nov 22 '21 at 12:36
  • @Math, too late :-(. I will not correct my answer again. Since I (as well this is done in other answer too) emphysise. that provided code is starting point, from where you can change, improve, etc. code that will gives what you after. – Zarko Nov 22 '21 at 12:52
  • @Zarko I'll just use your answer.. – Math Nov 22 '21 at 12:56
  • @Math, really? If so, than you may consider to accept it ;-) – Zarko Nov 22 '21 at 17:12
  • @Zarko When I tried it in a new document it worked but when I tried using it in my document I got the following error: `! Missing \endcsname inserted. \begingroup l.2848 ... \end{gathered}$"] (B.west)` – Math Nov 25 '21 at 12:41
  • @Math, sorry, I have any information about your document, so it is hard to say, what you doing wrong in it. Do you in preamble of your document load package amsmath? – Zarko Nov 25 '21 at 12:52
  • @Zarko I will attach as an edit in the question my preamble. – Math Nov 25 '21 at 12:53
  • @Zarko I have added to the edit in the original post. I have 2 questions: 1) how do I flip the $\epsilon I_1$ such that it reads left to right? 2) hopefully you can fix the figure using my preamble. Thank you :) – Math Nov 25 '21 at 13:14
  • @Math, do you really need al those packages? Somme of them are obsolete, some are loaded twice, etc. I strongly suggest you to cleanup your preamble. However, I test my answer with your preamble as it is. Compilation went fine, no errors, no warnings. I don't know what you do that you at compilation get errors. – Zarko Nov 25 '21 at 13:34
  • @Zarko this was a example given by my lecturer(he's old) so I didn't mess with it.. I will clean it up though. In my document it doesn't seem to work.. maybe I will post a separate question. In the meantime can you fix the arrow from $I_1$ to $I_2$ so that it reads "properly"? Also can we shorten the arrow from $J$ to $A$ otherwise it exceeds my margins – Math Nov 25 '21 at 13:38
  • @Math, new problem, new question :-) ! Image produced by my MWE reproduce image you showed in question. You can reduce distance between nodes by changes of node distance accordingly . It id defined as node distance = <vertical distance> and <horizontal distance> – Zarko Nov 25 '21 at 13:54
  • @Zarko I don't want to change all the other nodes horizontal spacing, i only wan to change the last nodes. – Math Nov 25 '21 at 14:22
  • @Math, please read tikz package documentation, at least first tutorial and than TikZ ist kein Zeichenprogramm or Minimal introduction to TikZ (unofficial)(use google to fint it on CTAN) and make yourself more familiar withtikz`. This is very elemetary knowledge about Tik*Z. It may help right=<desired distance> of coordinate> You can not expect that answers here will tech basic of package. – Zarko Nov 25 '21 at 15:55
  • @Zarko Can you have a look at a similar question: https://tex.stackexchange.com/questions/647934/how-to-draw-this-tikz-figure?noredirect=1#comment1614859_647934 – Math Jun 16 '22 at 13:47
  • @Math, it has very nice answer (+1) with simple code. I would use it . However, you can draw it as automaton, but code will not be so simple ... – Zarko Jun 16 '22 at 13:57
  • @Zarko But i want to be consistent in my document so as your answer here was really nice for an earlier section in my document, I'd appreciate if you could draw it again :) – Math Jun 16 '22 at 13:59
4

Since you provided something to work with, let me give you a first approach. I did not finish the drawing, since I only wanted to provide some ideas and also some parts of your scan are really hard to read.

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

\usetikzlibrary{positioning, arrows.meta}

\begin{document}

\begin{tikzpicture}[node distance=2.5cm, on grid] \tikzset{ font=\footnotesize, > = {Stealth[scale=1.5]}, mynode/.style = {rectangle, draw, minimum width=8mm, minimum height=8mm, inner sep=0pt, font=\normalsize}, label/.style = {circle, fill=white, inner sep=0.25pt}, }

\node [mynode] (A1) {S}; \node [mynode, above right=of A1] (B1) {$I_1$}; \node [mynode, below right=of A1] (C1) {$I_2$}; \node [mynode, above right=of C1] (D1) {$J$}; \node [mynode, right=of D1] (E1) {$A$};

\draw [<-] (A1) -- ++(-1,0) node[left] {$J$};

\draw [->] (A1) -- node[right] {$z$} (B1); \draw [->] ([xshift=-2.5mm]A1.north east) -- node[label] {$y$} ([yshift=2.5mm]B1.south west); \draw [->] ([xshift=-5mm]A1.north east) -- node[left] {$x$} ([yshift=5mm]B1.south west);

\draw [->] ([xshift=-1.5mm]B1.south) -- node[left] {$\epsilon$} ([xshift=-1.5mm]C1.north); \draw [->] ([xshift=1.5mm]B1.south) -- ++(0,-.5) node[below] {$\mu_{I_1}$};

\draw [->] (A1) -- ++(0,-1) node[below] {$\mu_S$};

% ...

\end{tikzpicture}

\end{document}

enter image description here

You should probably get familiar with the options yshift and xshift that allow you to shift a node from its current position. Also, you should probably be aware of anchors. Each node comes with a set of anchors such as north east which would be the upper right corner of the node. You can refer to these anchors by appending them using a dot to the node name.