I drew my compartmental diagram in Microsoft office word, used a snipping tool to capture the diagram and later transferred it to latex using using \includegraphics. However I have been instructed by my supervisor to draw the diagram in latex directly. I have no knowledge about this. I need help on the code to be used in drawing the diagram.
Attached is the compartmental diagram.

Asked
Active
Viewed 797 times
2
-
4Hi and welcome to the site. Questions that ask for drawing a diagram without any attempt are typically disregarded unless a volunteer user of the site finds time and willingness to draw. You might get more help by providing a snippet code with an initial attempt and focus the question on the parts where you find difficulty. Diagrams like this are simple and there is a wealth of examples in the web from where you can start. See for example How to draw graphs in LaTeX? – Claudio Fiandrino Mar 02 '21 at 08:15
-
2Adding to @ClaudioFiandrino comment, there is a tutorial in the TikZ manual which teaches you to do this kind of graph step-by-step. https://ctan.org/pkg/pgf?lang=en – Rmano Mar 02 '21 at 08:27
-
@RUKUNDOISAAC an answer without labels is below for your consideration – js bibra Mar 02 '21 at 11:31
-
Thank you @js bibra, I can now build from here. Any challenges, I will get back to you. – RUKUNDO ISAAC Mar 02 '21 at 12:44
2 Answers
3
Here's how I would draw this. The blue nodes are linked to the lines so moving the nodes should move all the lines as well. The styles of the arrows and nodes can be changed by changing part of \tikzset{<name>/.style={<style>}}.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\tikzset{node basic/.style={draw, ultra thick, blue, fill=blue!50, text=white, minimum size=2em}}
\tikzset{node circle/.style={node basic, circle}}
\tikzset{line basic/.style={very thick, ->}}
\tikzset{red dash/.style={line basic, dash dot, red}}
\tikzset{green dash/.style={line basic, dash dot, green}}
\tikzset{black dash/.style={line basic, dash dot}}
\tikzset{green line/.style={dash dot, green, ->}}
% Nodes
\node[node basic] (Q1) at (0, 0) {\(Q_1\)};
\node[node basic] (Q2) at (2, 0) {\(Q_2\)};
\node[node circle] (B1) at (-2, -3) {\(B_1\)};
\node[node circle] (B2) at (1, -3) {\(B_2\)};
\node[node circle] (B3) at (4, -3) {\(B_3\)};
% Red arrows
\draw[red dash] (B1.north) -- (Q1.south west) node[midway, left] {\scriptsize\(\alpha_1B_1\)};
\draw[red dash] (B2.north) -- (Q1.south) node[pos=0.7, left] {\scriptsize\(\alpha_2B_2\)};
\draw[red dash] (B3.north) -- (Q1.south east) node[midway, below] {\scriptsize\(\alpha_3B_3\)};
% Green Arrows
\draw[green dash] (B1.north) -- (Q2.south west) node[midway, below] {\scriptsize\(\gamma_1B_1\)};
\draw[green dash] (B2.north) -- (Q2.south) node[pos=0.2, right] {\scriptsize\(\gamma_2B_2\)};
\draw[green dash] (B3.north) -- (Q2.south east) node[midway, above right] {\scriptsize\(\gamma_2B_2\)};
% Black arrows
% Between Q
\draw[line basic] (Q1.west) -- ($(Q1.west) - (1, 0)$) node[left] {\(\delta(B_2 + B_3)\)};
\draw[line basic] ($(Q2.east)!0.5!(Q2.north east)$) -- ($(Q2.east)!0.5!(Q2.north east) + (1, 0)$) node[right] {\(\varepsilon Q_2\)};
\draw[line basic] ($(Q2.east)!0.5!(Q2.south east)$) -- ($(Q2.east)!0.5!(Q2.south east) + (1, 0)$) node[right] {\(\psi(B_2 + B_3)\)};
% Between B
\draw[line basic] (Q1.east) -- (Q2.west) node[midway, above] {\(\eta Q_1\)};
\draw[line basic] (B1.east) -- (B2.west) node[midway, below] {\(p_1B_1\)};
\draw[line basic] (B2.east) -- (B3.west) node[midway, below] {\(p_2B_2\)};
% Into/out of B
\draw[line basic] ($(B1.south west) - (0.5, 0.5)$) -- (B1.south west) node[pos=0, below] {\(\tau_1\Lambda\)};
\draw[line basic] ($(B2.south west) - (0.5, 0.5)$) -- (B2.south west) node[pos=0, below] {\(\tau_2\Lambda\)};
\draw[line basic] ($(B3.south west) - (0.5, 0.5)$) -- (B3.south west) node[pos=0, below] {\(\tau_3\Lambda\)};
\draw[line basic, <-] ($(B1.south east) - (-0.5, 0.5)$) -- (B1.south east) node[pos=0, below] {\(\mu_1B_1\)};
\draw[line basic, <-] ($(B2.south east) - (-0.5, 0.5)$) -- (B2.south east) node[pos=0, below] {\(\mu_2B_2\)};
\draw[line basic, <-] ($(B3.south east) - (-0.5, 0.5)$) -- (B3.south east) node[pos=0, below] {\(\mu_3B_3\)};
% f(N)B_2
\draw[line basic, dash dot] (B2.north west) .. controls ($(B2.west)!0.5!(B1.east) + (0, 0.5)$) .. (B1.north east) node[midway, above] {\footnotesize\(f(N)B_2\)};
\end{tikzpicture}
\end{document}
Willoughby
- 3,649
-
Fantastic! Thank you @Willoughby. This is the real diagram I needed. – RUKUNDO ISAAC Mar 02 '21 at 12:46
-
0
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning,calc, arrows.meta}
\usetikzlibrary {shapes,matrix}
\usetikzlibrary {graphs, quotes}
\begin{document}
\begin{tikzpicture}[
terminal/.style={
circle,
minimum size=1.5cm,
very thick,
draw=blue,
anchor=center,
},
terminall/.style={
% circle,
minimum size=1.5cm,
very thick,
draw=blue,
anchor=center,
},
ass/.style={
->,>=stealth,line width=2pt, black
},
ass1/.style={
->,>=stealth,line width=2pt, green!50!black,dash pattern={on 7pt off 2pt on 1pt off 3pt},
},
ass2/.style={
->,>=stealth,line width=2pt, red!50!black,dash pattern={on 7pt off 2pt on 1pt off 3pt},
},
bigass/.style={
ass,out=155,in=15,looseness=1.1,dash pattern={on 7pt off 2pt on 1pt off 3pt}
},
]
\matrix[row sep=3cm,column sep=2cm] {%
%
% First row:
&
&
\node [terminall](q1) {Q\textsubscript{1}}; &
&
\node [terminall](q2) {Q\textsubscript{2}};
& \\
% Second row:
&
\node [terminal](b1) {B\textsubscript{1}}; & &
\node [terminal](b2) {B\textsubscript{2}};&&
\node [terminal](b3) {B\textsubscript{3}};&
\\
%
};
\draw (b1) edge[ass] (b2);
\draw (b2) edge[ass] (b3);
\draw (q1) edge[ass] (q2);
\draw ($(q2.east)+(0pt,6pt)$)coordinate(aux) edge[ass]($(aux)+(3cm,0)$);
\draw ($(q2.east)+(0pt,-6pt)$)coordinate(aux1) edge[ass]($(aux1)+(3cm,0)$);
\draw ($(q1.west)+(0pt,3pt)$)coordinate(aux2) edge[ass]($(aux2)+(-3cm,0)$);
\draw (b1) edge[ass2] (q1);
\draw (b2) edge[ass2] (q1);
\draw (b3) edge[ass2] (q1);
\draw (b1) edge[ass1] (q2);
\draw (b2) edge[ass1] (q2);
\draw (b3) edge[ass1] (q2);
\draw (b2) edge[bigass] (b1);
\draw (b2.315) edge[ass]++(315:1cm);
\draw (b1.315) edge[ass]++(315:1cm);
\draw (b3.315) edge[ass]++(315:1cm);
\draw ($(b2.215)+(215:1cm)$)edge[ass](b2.215);
\draw ($(b1.215)+(215:1cm)$)edge[ass](b1.215);
\draw ($(b3.215)+(215:1cm)$)edge[ass](b3.215);
\end{tikzpicture}
\end{document}
js bibra
- 21,280

