|
楼主 |
kuing
发表于 2016-11-22 16:02
二、流程图- \usepackage{amsmath}
- \usepackage{tikz}
- \usetikzlibrary{
- shapes.geometric, %几何形状
- calc, %计算
- positioning %用于定位
- }
- \tikzset{
- every picture/.style={
- >=latex,
- node distance=5mm and 5mm
- %有无and的区别见手册positioning部分
- }}
- %定义框形状
- \tikzstyle{SS} %开始结束
- =[rounded corners, draw]
- \tikzstyle{IO} %输入输出
- =[trapezium, trapezium left angle=70, trapezium right angle=110, draw]
- \tikzstyle{NR} %内容
- =[draw]
- \tikzstyle{PD} %判断
- =[diamond, aspect=4, draw, inner sep=1.5pt]
复制代码 %例1- \begin{tikzpicture}[->]
- %放框
- \node[SS](start){开始};
- \node[IO, below=of start](in){输入$N$};
- \node[NR, below=of in](n1){$k=1$, $S=0$};
- \node[NR, below=of n1](n2){$S=S+\dfrac1{k(k+1)}$};
- \node[NR, right=of n2](n3){$k=k+1$};
- \node[PD, below=of n2](pd){$k<N$};
- \node[IO, below=of pd](out){输出$S$};
- \node[SS, below=of out](stop){结束};
- %连线
- \path
- (start) edge (in)
- (in) edge (n1)
- (n1) edge (n2)
- (n2) edge (pd)
- (pd) edge node[right]{否}(out)
- (out) edge (stop);
- \draw (pd.east)node[below]{是} -| (n3);
- \draw (n3) |- ($(n1.south)!0.5!(n2.north)$);
- \end{tikzpicture}
复制代码 效果:
%例2- \begin{tikzpicture}[->]
- \node[SS](start){开始};
- \node[NR, below=of start](n1){$a=1$};
- \node[NR, below right=1mm and 5mm of n1](n2){$a=a^2+2$};
- \node[PD, below=8mm of n1](pd){$a<10$?};
- \node[IO, below=of pd](out){输出$a$};
- \node[SS, below=of out](stop){结束};
- \path (start) edge (n1)
- (n1) edge (pd)
- (pd) edge node[right]{否}(out)
- (out) edge (stop);
- \draw (pd.east)node[below]{是} -| (n2);
- \draw (n2) -- (n2-|n1);
- \end{tikzpicture}
复制代码 效果:
%例3- \begin{tikzpicture}[->]
- \node[SS](start){开始};
- \node[IO, below=of start](in){输入$x$, $t$};
- \node[NR, below=of in](n1){$M=1$, $S=3$, $k=1$};
- \node[PD, below=of n1](pd){$k\le t$};
- \node[NR, on grid, below left=1cm and 2cm of pd](n3){$M=\dfrac Mkx$};
- \node[IO, on grid, below right=1cm and 2cm of pd](out){输出$S$};
- \node[NR, below=of n3](n4){$S=M+S$};
- \node[NR, below=of n4](n5){$k=k+1$};
- \node[SS, below=of out](stop){结束};
- \path (start) edge (in)
- (in) edge (n1)
- (n1) edge (pd)
- (n3) edge (n4)
- (n4) edge (n5)
- (out) edge (stop);
- \draw (pd) -| node[left]{是} (n3);
- \draw (pd) -| node[right]{否} (out);
- \draw (n5.west)--++(-0.5,0) |- ($(n1.south)!0.5!(pd.north)$);
- \end{tikzpicture}
复制代码 效果:
更多实例见测试文档:
LiuCT.tex
(5.25 KB, 下载次数: 988)
|
|