使用LaTex编写流程图

简单介绍如何使用$\LaTeX$进行流程图的绘制

效果

代码实现

\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

$\LaTeX$中绘图均要引入tikz宏包

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

对节点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);

属性

```(decision1):箭头的其实位置
### 线型
--:直线
|-:先竖线后横线
-|:向横线后竖线
### 文字:如果需要在箭头上添加文字 ```{yes}:需要添加的文字

文字的位置,上南下北左东右西(与地图方位不一致)

[anchor=east]:
[anchor=south]:
[anchor=west]:
[anchor=north]:
[anchor=center]:

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!