如何在流程图的起点处画箭头?

如何在流程图的起点处画箭头?

我不知道如何在流程图中的开头和结尾绘制箭头。我使用了以下方法

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\begin{document}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{process} = [rectangle,rounded corners, minimum width=2.5cm, minimum height=1.5cm, text centered, text width=2cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=1.5cm, minimum height=1cm, text centered, text width=2cm, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{tikzpicture}[node distance=1.5cm]
 \node (s1)[process]{Comp $C_1(t)$};
\node (s2)[process,right of =s1, xshift=2cm]{Comp  $C_2(t)$};
\node (s3)[process, right of =s2, xshift=2cm]{Comp $C_3(t)$};
\node (s4)[process,above of=s3, yshift=2cm]{Comp $C_4(I)$};
\node (s5)[process,right of =s3, xshift=2cm]{Comp $C_5(t)$};
\draw [arrow] (s1) -- node[above] {$\beta $} (s2);
\draw [arrow] (s2) -- node[above] {$\gamma$} (s3);
\draw [arrow] (s3) -- node[right] {$r$} (s4);
\draw [arrow] (s3) -- node[above] {$\mu$} (s5);
\draw [arrow] (s4) -- node[above] {$r$} (s5);
\end{tikzpicture}

\end{document}  

但我想要下图。

在此处输入图片描述

答案1

您可以使用相对坐标来实现这一点。例如,++(1,0)是前一个坐标右侧 1 个单位的点,因此\draw (s1.south) -- ++(0,-1);从 的底端向下绘制一条 1 厘米长的线s1

在下面的代码中,我还做了其他一些修改。一般建议使用\tikzset{foo/.style={...}, ...}over \tikzstyle{foo}=[...],所以我做了修改。

最值得注意的是,我添加了positioning库,并将例如更改为right of=s1,xshift=2cmright=of s1使用该库和略有不同的语法,计算节点边缘之间的距离,因此您不需要xshift

在此处输入图片描述

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, positioning}
\tikzset{
startstop/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
process/.style={rectangle,rounded corners, minimum width=2.5cm, minimum height=1.5cm, text centered, text width=2cm, draw=black, fill=orange!30},
decision/.style={diamond, minimum width=1.5cm, minimum height=1cm, text centered, text width=2cm, draw=black, fill=green!30},
arrow/.style={thick,->,>=stealth}
}
\begin{document}

\begin{tikzpicture}[node distance=1cm]
\node (s1)[process]{Comp $C_1(t)$};
\node (s2)[process, right=of s1]{Comp  $C_2(t)$};
\node (s3)[process, right=of s2]{Comp $C_3(t)$};
\node (s4)[process, above=of s3]{Comp $C_4(I)$};
\node (s5)[process, right=of s3]{Comp $C_5(t)$};
\draw [arrow] (s1) -- node[above] {$\beta $} (s2);
\draw [arrow] (s2) -- node[above] {$\gamma$} (s3);
\draw [arrow] (s3) -- node[right] {$r$} (s4);
\draw [arrow] (s3) -- node[above] {$\mu$} (s5);
\draw [arrow] (s4) -- node[above] {$r$} (s5);

\draw [arrow, <-] (s1.west) -- node[above] {A} ++(-1cm,0);
\draw [arrow] (s5.east) -- node[above] {B} ++(1cm,0);
\foreach \i/\t in {1/C,2/D,3/E,5/F}
  \draw [arrow] (s\i.south) -- node[left] {\t} ++(0,-1cm);

\end{tikzpicture}
\end{document}

相关内容