![如何使用 TikZ 为隔间模型流程图制作对角箭头?](https://linux22.com/image/396796/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20TikZ%20%E4%B8%BA%E9%9A%94%E9%97%B4%E6%A8%A1%E5%9E%8B%E6%B5%81%E7%A8%8B%E5%9B%BE%E5%88%B6%E4%BD%9C%E5%AF%B9%E8%A7%92%E7%AE%AD%E5%A4%B4%EF%BC%9F.png)
到目前为止我有以下代码。
\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$};