# How can I make diagonal arrows using TikZ for a compartment model flow diagram?

I am trying to create this diagram using TikZ (to make it neater).

So far I have the following code.

\documentclass[tikz,margin=2mm]{standalone}
\usepackage[utf8]{inputenc}
\usetikzlibrary{arrows,positioning}
\definecolor{boxcolor}{HTML}{B9DCFF}
\begin{document}
\pagestyle{empty}
%
\tikzstyle{block}=[draw, fill=boxcolor, minimum size=2em, text width = 2.5cm, align = center, minimum height = 2.5cm]
\tikzstyle{arrow}=[->, red, text = black]

\begin{tikzpicture}[auto, >=latex']
\node [block, pin={[arrow] above left:$m$}] (s) {Susceptible \\ $S$};
\node [block, right = 2.5cm of s] (p) {Infected, \\ Presymptomatic \\ $P$};
\node [block, above right = 0.25cm and 1cm of p] (a) {Infected, \\ Asymptomatic \\ $A$};
\node [block, below right = 0.25cm and 1cm of p] (i) {Infected, \\ Sympomatic \\ $I$};
\node [block, right = 1cm of a] (r) {Recovered, \\ Immune \\ $R$};
\node [block, right = 1cm of i] (d) {Dead \\ $D$};

\draw [arrow] (s) -- node [above] {$b_PPS+b_AAS$} node [below] {$+b_IIS$} (p);
\draw [arrow] (p.north) |- ++(0cm,+1.5cm) -- node [above] {$fg_PP$} (a.west);
\draw [arrow] (p.south) |- ++(0cm,-1.5cm) -- node [below] {$(1-f)g_P P$} (i.west);
\draw [arrow] (a) -- node [above] {$g_A A$} (r);
\draw [arrow] (i) -- node [below] {$d g_I I$} (d);
\draw [arrow] (i) -- node [above, xshift = 1cm,yshift = -0.2cm] {$(1-d) g_I I$} (r);
\draw [arrow] (r.north) |- ++(0cm,+1.0cm) -- node [above, pos = 0.75mm] {$wR$} ++(-3cm,0cm) -| (s);

\end{tikzpicture}

\end{document}


Which produces this.

However, I am having a hard time figuring out how to add the arrows that either point into or out of a node without connecting to another node (e.g. the arrow labeled $m$ which only goes into the Susceptible node).

What would be the best way to add these arrows?

You need to set pin edge appropriately.

\documentclass[tikz,margin=2mm]{standalone}
\usepackage[utf8]{inputenc}
\usetikzlibrary{arrows,positioning}
\definecolor{boxcolor}{HTML}{B9DCFF}
\begin{document}
\pagestyle{empty}
%
\tikzset{block/.style={draw, fill=boxcolor, minimum size=2em, text width =
2.5cm, align = center, minimum height = 2.5cm},
arrow/.style={->, red, text = black}}

\begin{tikzpicture}[auto, >=latex']
\node [block, pin={[pin edge={arrow,<-}] above left:$m$}] (s) {Susceptible \\ $S$};
\node [block, right = 2.5cm of s] (p) {Infected, \\ Presymptomatic \\ $P$};
\node [block, above right = 0.25cm and 1cm of p] (a) {Infected, \\ Asymptomatic \\ $A$};
\node [block, below right = 0.25cm and 1cm of p] (i) {Infected, \\ Sympomatic \\ $I$};
\node [block, right = 1cm of a] (r) {Recovered, \\ Immune \\ $R$};
\node [block, right = 1cm of i] (d) {Dead \\ $D$};

\draw [arrow] (s) -- node [above] {$b_PPS+b_AAS$} node [below] {$+b_IIS$} (p);
\draw [arrow] (p.north) |- ++(0cm,+1.5cm) -- node [above] {$fg_PP$} (a.west);
\draw [arrow] (p.south) |- ++(0cm,-1.5cm) -- node [below] {$(1-f)g_P P$} (i.west);
\draw [arrow] (a) -- node [above] {$g_A A$} (r);
\draw [arrow] (i) -- node [below] {$d g_I I$} (d);
\draw [arrow] (i) -- node [above, xshift = 1cm,yshift = -0.2cm] {$(1-d) g_I I$} (r);
\draw [arrow] (r.north) |- ++(0cm,+1.0cm) -- node [above, pos = 0.75mm] {$wR$} ++(-3cm,0cm) -| (s);

\end{tikzpicture}

\end{document}


If you want all pins of that type, use every pin:

\begin{tikzpicture}[auto, >=latex',every pin/.style={pin edge={arrow,<-}}]
\node [block, pin={above left:$m$}] (s) {Susceptible \\ $S$};

• Excellent, thank you! – wz-billings Jun 3 '19 at 16:01