带线的SEIR模型问题

带线的SEIR模型问题

你好,我无法改变这个 tikzpicture 中线条的距离:

\begin{tikzpicture}[node distance=2cm, auto,
>=Latex,every node/.append style={align=center},
int/.style={draw, minimum size=1.6cm}]
\node [int] (a) {$S$};
\node (b) [left of=a,node distance=2cm, coordinate] {a};
\node (c1) [below of=c,node distance=2cm, coordinate] {c1}; 
\node [int] (c) [right of=a] {$E$};
\node (c2) [below of=c,node distance=2cm, coordinate] {c2};  
\node [int] (d) [right of=c] {$I$};
\node (c3) [below of=d,node distance=2cm, coordinate] {c3};     
\node [int] (e) [right of=d] {$R$};
\node (c4) [below of=e,node distance=2cm, coordinate] {c4};

\path[->] (b) edge node {$\mu$} (a);
\draw[->] (a) edge node {$\beta$} (c);
\draw[->] (c) edge node {$\sigma$} (d);
\draw[->] (d) edge node {$\gamma$} (e);  
\draw[->] (a) edge node {śmierć} (c1);   
\draw[->] (c) edge node {śmierć} (c2);  
\draw[->] (d) edge node {śmierć} (c3);    
\draw[->] (e) edge node {śmierć} (c4);    
\end{tikzpicture}

我想让所有线条看起来都一样,长度也一样。有人能帮我解决这个问题吗?

答案1

欢迎!您可能确实想使用定位库。它的语法是below=<distance> of ...而不是below of=...

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\begin{tikzpicture}[node distance=1.2cm and 0.5cm, auto,
>=Latex,every node/.append style={align=center}, 
int/.style={draw, minimum size=1.6cm}] 
\node [int] (a) {$S$}; 
\node (b) [left of=a, coordinate] {a}; 
\node [int] (c) [right=of a] {$E$}; 
\node (c1) [below=of a, coordinate] {c1}; 
\node (c2) [below=of c, coordinate] {c2};
\node [int] (d) [right=of c] {$I$}; 
\node (c3) [below=of d, coordinate] {c3};
\node [int] (e) [right=of d] {$R$}; 
\node (c4) [below=of e, coordinate] {c4};
\path[->] (b) edge node {$\mu$} (a)
   (a) edge node {$\beta$} (c) edge node {\'smier\'c} (c1)
   (c) edge node {$\sigma$} (d) edge node {\'smier\'c} (c2) 
   (d) edge node {$\gamma$} (e)  edge node {\'smier\'c} (c3)  
   (e) edge node {\'smier\'c} (c4);    
\end{tikzpicture} 
\end{document}

在此处输入图片描述

您可以使用该quotes库来免去编写一些node命令的麻烦,但是在这个例子中,我认为这不值得。

如果你想要一些简化,你可以这样做

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,chains}
\begin{document}
\begin{tikzpicture}[node distance=1.2cm and 0.5cm, auto,
>=Latex,every node/.append style={align=center}, 
int/.style={draw, minimum size=1.6cm},arj/.style={->}] 
\begin{scope}[start chain=R going right,
    int/.append style={on chain,join=by arj,
    append after command={(\tikzlastnode) edge[->,edge label={\'smier\'c}] ++ (0,-2)}},
    el/.initial=,
    arj/.append style={edge label={$\pgfkeysvalueof{/tikz/el}$}}]
\path   coordinate[on chain](b)  [el=\mu]
   node [int] (a) {$S$} [el=\beta]
   node [int] (c) {$E$} [el=\sigma] 
   node [int] (d) {$I$} [el=\gamma]
   node [int] (e) {$R$};
\end{scope}   
\end{tikzpicture} 
\end{document}

在此处输入图片描述

相关内容