概述
使用latex的tikz包绘制流程图
首先需要使用tikz包
usepackage{xcolor}
usepackage{tikz}
usetikzlibrary{arrows,shapes,chains}
然后在figure中放置流程图
1.定义不同的形状(一般有基本形状,判断形状,像素点)
tikzstyle{format}=[rectangle,draw,thin,fill=white]
%定义语句块的颜色,形状和边
tikzstyle{test}=[diamond,aspect=2,draw,thin]
%定义条件块的形状,颜色
tikzstyle{point}=[coordinate,on grid,]
%像素点,用于连接转移线
2.放置node,(图形元素)
%第一个node node[样式] (标号){内容}
node[format] (start){Start};
%后面的node,使用below of=标号,right of=标号,left of=标号,表示位置,可以加上node distance=xmm调节位置.
node[format,below of=start,node distance=7mm] (define){Some defines};
3.连线draw
%使用标号.东南西北表示链接该node的位置,[->,dashed]表示是否带箭头,虚线.–,-|,|-表示连线拐弯情况
draw[->] (n0.south) – (n1); 带箭头实线
draw[-] (n0.south) – (n1); 不带箭头实线
draw[<->] (n0.south) – (n1.north); 双箭头
draw[<-,dashed] (n1.south) – (n2.north); 带箭头虚线
draw[<-] (n0.south) to node{Yes} (n1.north); 带字,字在箭头方向右边
draw[->] (n1.north) to node{Yes} (n0.south); 带字,字在箭头方向左边
draw[->] (n1.north) to[out=60,in=300] node{Yes} (n0.south); 曲线
draw->,draw=red–(n1); 带颜色的线
draw[->] (start)–(define);
例子
documentclass[a4paper,UTF8]{article}
usepackage{xcolor}
usepackage{tikz}
usetikzlibrary{arrows,shapes,chains}
begin{document}
centering
begin{figure}
scriptsize
tikzstyle{format}=[rectangle,draw,thin,fill=white]
%定义语句块的颜色,形状和边
tikzstyle{test}=[diamond,aspect=2,draw,thin]
%定义条件块的形状,颜色
tikzstyle{point}=[coordinate,on grid,]
%像素点,用于连接转移线
begin{tikzpicture}%[node distance=10mm,auto,>=latex',thin,start chain=going below,every join/.style={norm},]
%start chain=going below指明了流程图的默认方向,node distance=8mm则指明了默认的node距离。这些可以在定义node的时候更改,比如说
%node[point,right of=n3,node distance=10mm] (p0){};
%这里声明了node p0,它在node n3 的右边,距离是10mm。
node[format] (start){Start};
node[format,below of=start,node distance=7mm] (define){Some defines};
node[format,below of=define,node distance=7mm] (PCFinit){PCF8563 Initialize};
node[format,below of=PCFinit,node distance=7mm] (DS18init){DS18 Initialize};
node[format,below of=DS18init,node distance=7mm] (LCDinit){LCD Initialize};
node[format,below of=LCDinit,node distance=7mm] (processtime){Processtime};
node[format,below of=processtime,node distance=7mm] (keyinit){Key Initialize};
node[test,below of=keyinit,node distance=15mm](setkeycheck){Check Set Key};
node[point,left of=setkeycheck,node distance=18mm](point3){};
node[format,below of=setkeycheck,node distance=15mm](readtime){Read Time};
node[point,right of=readtime,node distance=15mm](point4){};
node[format,below of=readtime](processtime1){Processtime};
node[format,below of=processtime1](gettemp){Get Temperature};
node[format,below of=gettemp](display){Display All Data};
node[format,right of=setkeycheck,node distance=40mm](setsetflag){Set SetFlag=1};
node[format,below of=setsetflag](setinit){Set Mode Initialize};
node[format,below of=setinit](checksetting){Checksetting()};
node[test,below of=checksetting,node distance=15mm](savecheck){Check Save Key};
node[format,below of=savecheck,node distance=15mm](clearsetflag){Clear SetFlag=0};
node[format,below of=clearsetflag](settime){Set Time};
node[point,below of=display,node distance=7mm](point1){};
node[point,below of=settime,node distance=7mm](point2){};
%node[format] (n0) at(4,4){A}; 直接指定位置
%定义完node之后进行连线,
%draw[->] (n0.south) -- (n1); 带箭头实线
%draw[-] (n0.south) -- (n1); 不带箭头实线
%draw[<->] (n0.south) -- (n1.north);
双箭头
%draw[<-,dashed] (n1.south) -- (n2.north); 带箭头虚线
%draw[<-] (n0.south) to node{Yes} (n1.north);
带字,字在箭头方向右边
%draw[->] (n1.north) to node{Yes} (n0.south);
带字,字在箭头方向左边
%draw[->] (n1.north) to[out=60,in=300] node{Yes} (n0.south);
曲线
%draw[->,draw=red](n2)--(n1);
带颜色的线
draw[->] (start)--(define);
draw[->] (define)--(PCFinit);
draw[->](PCFinit)--(DS18init);
draw[->](DS18init)--(LCDinit);
draw[->](LCDinit)--(processtime);
draw[->](processtime)--(keyinit);
draw[->](keyinit)--(setkeycheck);
draw[->](setkeycheck)--node[above]{Yes}(setsetflag);
draw[->](setkeycheck) --node[left]{No} (readtime);
draw[->](readtime)--(processtime1);
draw[->](processtime1)--(gettemp);
draw[->](gettemp)--(display);
draw[-](display)--(point1);
draw[-](point1)-|(point3);
draw[->](point3)--(setkeycheck.west);
draw[->](setsetflag)--(setinit);
draw[->](setinit)--(checksetting);
draw[->](checksetting)--(savecheck);
draw[->](savecheck)--node[left]{Yes}(clearsetflag);
draw[->](savecheck.west)|-node[left]{No}(checksetting);
draw[->](clearsetflag)--(settime);
draw[-](settime)--(point2);
draw[-](point2)-|(point4);
draw[->](point4)--(readtime.east);
end{tikzpicture}
end{figure}
end{document}
最后
以上就是时尚冥王星为你收集整理的Latex 绘制流程图的全部内容,希望文章能够帮你解决Latex 绘制流程图所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复