如何使用 TikZ 为隔间模型流程图制作对角箭头?

如何使用 TikZ 为隔间模型流程图制作对角箭头?

我正在尝试使用 TikZ 创建该图表(以使其更整洁)。 在此处输入图片描述

到目前为止我有以下代码。

\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}

从而产生了这个。

在此处输入图片描述

但是,我很难弄清楚如何添加指向节点或指向节点外的箭头而不连接到另一个节点(例如,标记为 $m$ 的箭头仅进入易受影响节点)。

添加这些箭头的最佳方法是什么?

答案1

您需要进行pin edge适当设置。

\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}

在此处输入图片描述

如果您想要该类型的所有引脚,请使用every pin

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

相关内容