Latex绘制流程图

使用Latex绘制原生的流程图

Posted by Elton on July 23, 2019

实现效果


流程图

codes


\documentclass[UTF8]{ctexart}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}
\pagestyle{empty} % 无页眉页脚

\tikzstyle{startstop} = [rectangle,rounded corners, minimum width=3cm,minimum height=1cm,text centered, draw=black,fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle = 70,trapezium right angle=110,minimum width=3cm,minimum height=1cm,text centered,draw=black,fill=blue!30]
\tikzstyle{process} = [rectangle,minimum width=3cm,minimum height=1cm,text centered,text width =3cm,draw=black,fill=orange!30]
\tikzstyle{decision} = [diamond,minimum width=3cm,minimum height=1cm,text centered,draw=black,fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{tikzpicture}[node distance=2cm]
\node (start) [startstop] {Start};
\node (input1) [io,below of=start] {Input};
\node (process1) [process,below of=input1] {Process 1};
\node (decision1) [decision,below of=process1,yshift=-0.5cm] {Decession 1};
\node (process2a) [process,below of=decision1,yshift=-0.5cm] {Process 2aaaaaa aaaaaaa aaaa};
\node (process2b) [process,right of =decision1,xshift=2cm] {Process 2b};
\node (out1) [io,below of=process2a] {Output};
\node (stop) [startstop,below of=out1] {Stop};

\draw [arrow] (start) -- (input1);
\draw [arrow] (input1) -- (process1);
\draw [arrow] (process1) -- (decision1);
\draw [arrow] (decision1) -- node[anchor=east] {yes} (process2a);
\draw [arrow] (decision1) -- node[anchor=south] {no} (process2b);
\draw [arrow] (process2b) |- (process1);
\draw [arrow] (process2a) -- (out1);
\draw [arrow] (out1) -- (stop);
\end{tikzpicture}

\end{document}

Using Package


\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

tikzstyle 定义node和箭头的属性


节点node


\tikzstyle{process} = [rectangle,minimum width=3cm,minimum height=1cm,text centered,text width =3cm,draw=black,fill=orange!30]

解析:

# 节点形状
rectangle:矩形,可加圆角(rounded corners)
trapezium:平行四边形
diamond:菱形
# 尺寸
minimum width
minimum height
# 文本
text centered:文本居中
# 文本宽度
text width=3cm:文本超过3cm时会自动换行
# 边框
draw
# 填充颜色
fill

箭头


\tikzstyle{arrow} = [thick,->,>=stealth]

解析:

# 线粗:
thick:粗
thin:细
# 箭头
->:反向箭头
<-:正向箭头
<->:双向箭头
# 虚线
dashed
# 箭头形状
>=stealth

创建节点


\node (decision1) [decision,below of=process1,yshift=-0.5cm] {Decession 1};

解析:

# name
(decision1):这个节点的name,后面需要用这个name调用这个节点。
# 属性
decision:需要调用的节点的属性
# 位置
below of=process1:定义节点的位置
left of:
right of:
# 偏移,对位置进行微调
yshift:
xshift:
# title
{Decession 1}:结果显示的标题

画箭头


\draw [arrow] (decision1) -- node[anchor=east] {yes} (process2a);

解析:

# 属性
[arrow]:需要调用的箭头的属性
(decision1):箭头的其实位置
(process2a):箭头的末端位置
# 线型
--:直线
|-:先竖线后横线
-|:向横线后竖线
# 文字:如果需要在箭头上添加文字
{yes}:需要添加的文字
# 文字的位置,上南下北左东右西(与地图方位不一致)
[anchor=east]:
[anchor=south]:
[anchor=west]:
[anchor=north]:
[anchor=center]: