\documentclass[UTF8]{ctexart}
\usepackage{tikz,mathpazo}
\usetikzlibrary{shapes.geometric, arrows}
\begin{document}\thispagestyle{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, 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 (in1) [io, below of=start] {Input1};\node (in2) [io, right of=in1, xshift=3.5cm] {Input2};\node (pro1) [process, below of=in1] {Process 1};\node (dec1) [decision, below of=pro1, yshift=-0.5cm] {Decision 1};\node (pro2a) [process, below of=dec1, yshift=-0.5cm] {Process 2a};\node (pro2b) [process, right of=dec1, xshift=3cm] {Process 2b};\node (out1) [io, below of=pro2a] {Output};\node (stop) [startstop, below of=out1] {Stop};%连接具体形状连接关系\draw [arrow](start) -- (in1);\draw [arrow](in1) -- (in2);\draw [arrow](in1) -- (pro1);\draw [arrow](pro1) -- (dec1);\draw [arrow](dec1) -- (pro2a);\draw [arrow](dec1) -- (pro2b);\draw [arrow](in2) -- (pro2b);\draw [arrow](dec1) -- node[anchor=east] {yes} (pro2a);\draw [arrow](dec1) -- node[anchor=south] {no} (pro2b);\draw [arrow](pro2b) |- (pro1);\draw [arrow](pro2a) -- (out1);\draw [arrow](out1) -- (stop);\end{tikzpicture}
\end{document}
第二种:使用tikzpicture和flowchart
\documentclass[UTF8]{ctexart} \usepackage{tikz,mathpazo} \usetikzlibrary{shapes.geometric, arrows} \usepackage{flowchart} \begin{document}\begin{tikzpicture}[font={\sf \small}]\def \smbwd{2cm}\thispagestyle{empty}%定义流程图的具体形状\node (start) at (0,0) [draw, terminal,minimum width=\smbwd, minimum height=0.5cm] {开始}; % 定义开始 \node (getdata) at (0,-1.5) [draw, predproc, align=left,minimum width=\smbwd,minimum height=1cm] {读取数据}; %定义预处理过程,读取数据\node (decide1) at (0,-3.5) [draw, decision, minimum width=\smbwd, minimum height=1cm] {判断条件1}; %定义判断条件\node (process1) at (3,-4.25) [draw, process, minimum width=\smbwd, minimum height=0.5cm] {处理过程1}; %定义处理过程\node (decide2) at (0,-6.5) [draw, decision, minimum width=\smbwd, minimum height=1cm] {判断条件2}; %定义数据存储\node (process2) at (3,-7.25) [draw, process, minimum width=\smbwd, minimum height=0.5cm] {处理过程2}; %定义处理过程\node (decide3) at (0,-9.5) [draw, decision, minimum width=\smbwd, minimum height=1cm] {判断条件3}; %定义数据存储\node (process3) at (3,-10.25) [draw, process, minimum width=\smbwd, minimum height=0.5cm] {处理过程3}; %定义处理过程\node (storage) at (3,-11.75) [draw, storage, minimum width=\smbwd, minimum height=0.5cm] {数据存储}; %定义数据存储\coordinate (point1) at (0,-5);\coordinate (point2) at (0,-8);\coordinate (point3) at (0,-11.75);\node (end) at (0,-12.75) [draw, terminal,minimum width=\smbwd,minimum height=0.5cm] {结束}; %定义结束%连接定义的形状,绘制流程图--表示垂直线,|表示箭头方向\draw[->] (start) -- (getdata);\draw[->] (getdata)-- (decide1);\draw[->] (decide1) -| node[above]{成立} (process1);\draw[->] (process1) |- (point1);\draw[->] (decide1)-- node[left]{否}(decide2);\draw[->] (decide2) -| node[above]{成立} (process2);\draw[->] (process2) |- (point2);\draw[->] (decide2)-- node[left]{否}(decide3);\draw[->] (decide3) -| node[above]{成立} (process3);\draw[->] (process3) -- (storage);\draw[->] (storage) -- (point3);\draw[->] (decide3) -- node[left]{否}(point3) -- (end);\end{tikzpicture} \end{document}
第三种:pgf-tik文档中的官方例程,将所有元素按照矩阵排列,接着使用path标注路径;
\documentclass[UTF8]{ctexart} \usepackage{tikz,mathpazo} \usetikzlibrary {arrows,shapes.geometric} \begin{document} \begin{tikzpicture}[auto,decision/.style={diamond, draw=blue, thick, fill=blue!20,text width=4.5em,align=flush center,inner sep=1pt},block/.style={rectangle, draw=blue, thick, fill=blue!20,text width=5em,align=center, rounded corners,minimum height=4em},line/.style={draw, thick, -latex',shorten >=2pt},cloud/.style={draw=red, thick, ellipse,fill=red!20,minimum height=2em}]\matrix [column sep=5mm,row sep=7mm]{% row 1\node [cloud] (expert){expert}; &\node [block] (init){initialize model}; &\node [cloud] (system){system}; \\% row 2& \node [block] (identify) {identify candidate model}; & \\% row 3\node [block] (update){update model}; &\node [block] (evaluate) {evaluate candidate models}; & \\% row 4& \node [decision] (decide) {is best candidate}; & \\% row 5& \node [block] (stop){stop}; & \\};\begin{scope}[every path/.style=line]\path (init)-- (identify);\path (identify) -- (evaluate);\path (evaluate) -- (decide);\path (update)|- (identify);\path (decide)-| node [near start] {yes} (update);\path (decide)-- node [midway] {no} (stop);\path [dashed] (expert)-- (init);\path [dashed] (system)-- (init);\path [dashed] (system)|- (evaluate);\end{scope} \end{tikzpicture} \end{document}
个人觉得第一种实现最简单,但是完全自动排版,不够灵活;第三种,逻辑简单,排版灵活强大;第二种基于flowchart使用限制较多,排版不够灵活,功能也一般,不建议使用。
