├── .gitignore ├── Makefile ├── README.md ├── demo.pdf ├── demo.tex ├── screenshot ├── flowchart01.png └── flowchart02.png ├── tikz-flowchart.dtx ├── tikz-flowchart.ins ├── tikz-flowchart.pdf └── tikz-flowchart.sty /.gitignore: -------------------------------------------------------------------------------- 1 | # -*- mode: gitignore; -*- 2 | 3 | # cancle release folder 4 | release* 5 | ./release/ 6 | /release/* 7 | ./release/* 8 | 9 | # ref folder 10 | # refs* 11 | # ./refs/ 12 | # /refs/* 13 | # ./refs/* 14 | 15 | # fonts folder 16 | ./fonts/ 17 | /fonts/* 18 | ./fonts/* 19 | 20 | # ======emacs editor====== 21 | *~ 22 | \#*\# 23 | /.emacs.desktop 24 | /.emacs.desktop.lock 25 | *.elc 26 | auto-save-list 27 | tramp 28 | .\#* 29 | 30 | # Org-mode 31 | .org-id-locations 32 | *_archive 33 | 34 | # flymake-mode 35 | *_flymake.* 36 | 37 | # eshell files 38 | /eshell/history 39 | /eshell/lastdir 40 | 41 | # elpa packages 42 | /elpa/ 43 | 44 | # reftex files 45 | *.rel 46 | 47 | # AUCTeX auto folder 48 | /auto/ 49 | 50 | # cask packages 51 | .cask/ 52 | dist/ 53 | 54 | # Flycheck 55 | flycheck_*.el 56 | 57 | # server auth directory 58 | /server/ 59 | 60 | # projectiles files 61 | .projectile 62 | 63 | # directory configuration 64 | .dir-locals.el 65 | 66 | # ======C programming====== 67 | 68 | # Prerequisites 69 | *.d 70 | 71 | # Object files 72 | *.o 73 | *.ko 74 | *.obj 75 | *.elf 76 | 77 | # Linker output 78 | *.ilk 79 | *.map 80 | *.exp 81 | 82 | # Precompiled Headers 83 | *.gch 84 | *.pch 85 | 86 | # Libraries 87 | *.lib 88 | *.a 89 | *.la 90 | *.lo 91 | 92 | # Shared objects (inc. Windows DLLs) 93 | *.dll 94 | *.so 95 | *.so.* 96 | *.dylib 97 | 98 | # Executables 99 | *.exe 100 | *.out 101 | *.app 102 | *.i*86 103 | *.x86_64 104 | *.hex 105 | 106 | # Debug files 107 | *.dSYM/ 108 | *.su 109 | *.idb 110 | *.pdb 111 | 112 | # Kernel Module Compile Results 113 | *.mod* 114 | *.cmd 115 | .tmp_versions/ 116 | modules.order 117 | Module.symvers 118 | Mkfile.old 119 | dkms.conf 120 | 121 | # ======Tex/LaTex====== 122 | ## Core latex/pdflatex auxiliary files: 123 | *.aux 124 | *.lof 125 | *.log 126 | *.lot 127 | *.fls 128 | *.out 129 | *.toc 130 | *.fmt 131 | *.fot 132 | *.cb 133 | *.cb2 134 | *.atfi 135 | .*.lb 136 | 137 | ## Core dtx auxiliary files: 138 | ##*.ins 139 | 140 | ## Intermediate documents: 141 | *.dvi 142 | *.xdv 143 | *-converted-to.* 144 | # these rules might exclude image files for figures etc. 145 | # *.ps 146 | # *.eps 147 | # *.pdf 148 | 149 | ## Generated if empty string is given at "Please type another file name for output:" 150 | .pdf 151 | 152 | ## Bibliography auxiliary files (bibtex/biblatex/biber): 153 | *.bbl 154 | *.bcf 155 | *.blg 156 | *-blx.aux 157 | *-blx.bib 158 | *.run.xml 159 | 160 | ## Build tool auxiliary files: 161 | *.fdb_latexmk 162 | *.synctex 163 | *.synctex(busy) 164 | *.synctex.gz 165 | *.synctex.gz(busy) 166 | *.pdfsync 167 | 168 | ## Build tool directories for auxiliary files 169 | # latexrun 170 | latex.out/ 171 | 172 | ## Auxiliary and intermediate files from other packages: 173 | # algorithms 174 | *.alg 175 | *.loa 176 | 177 | # achemso 178 | acs-*.bib 179 | 180 | # amsthm 181 | *.thm 182 | 183 | # beamer 184 | *.nav 185 | *.pre 186 | *.snm 187 | *.vrb 188 | 189 | # changes 190 | *.soc 191 | 192 | # cprotect 193 | *.cpt 194 | 195 | # elsarticle (documentclass of Elsevier journals) 196 | *.spl 197 | 198 | # endnotes 199 | *.ent 200 | 201 | # fixme 202 | *.lox 203 | 204 | # feynmf/feynmp 205 | *.mf 206 | *.mp 207 | *.t[1-9] 208 | *.t[1-9][0-9] 209 | *.tfm 210 | 211 | #(r)(e)ledmac/(r)(e)ledpar 212 | *.end 213 | *.?end 214 | *.[1-9] 215 | *.[1-9][0-9] 216 | *.[1-9][0-9][0-9] 217 | *.[1-9]R 218 | *.[1-9][0-9]R 219 | *.[1-9][0-9][0-9]R 220 | *.eledsec[1-9] 221 | *.eledsec[1-9]R 222 | *.eledsec[1-9][0-9] 223 | *.eledsec[1-9][0-9]R 224 | *.eledsec[1-9][0-9][0-9] 225 | *.eledsec[1-9][0-9][0-9]R 226 | 227 | # glossaries 228 | *.acn 229 | *.acr 230 | *.glg 231 | *.glo 232 | *.gls 233 | *.glsdefs 234 | *.hd 235 | 236 | # gnuplottex 237 | *-gnuplottex-* 238 | 239 | # gregoriotex 240 | *.gaux 241 | *.gtex 242 | 243 | # htlatex 244 | *.4ct 245 | *.4tc 246 | *.idv 247 | *.lg 248 | *.trc 249 | *.xref 250 | 251 | # hyperref 252 | *.brf 253 | 254 | # knitr 255 | *-concordance.tex 256 | # TODO Comment the next line if you want to keep your tikz graphics files 257 | *.tikz 258 | *-tikzDictionary 259 | 260 | # listings 261 | *.lol 262 | *.listing 263 | 264 | # makeidx 265 | *.idx 266 | *.ilg 267 | *.ind 268 | *.ist 269 | *.ilg 270 | 271 | # minitoc 272 | *.maf 273 | *.mlf 274 | *.mlt 275 | *.mtc[0-9]* 276 | *.slf[0-9]* 277 | *.slt[0-9]* 278 | *.stc[0-9]* 279 | 280 | # minted 281 | _minted* 282 | ./_minted-main/ 283 | /_minted-main/* 284 | 285 | ./_minted-cbook/ 286 | /_minted-cbook/* 287 | *.pyg 288 | 289 | # morewrites 290 | *.mw 291 | 292 | # nomencl 293 | *.nlg 294 | *.nlo 295 | *.nls 296 | 297 | # pax 298 | *.pax 299 | 300 | # pdfpcnotes 301 | *.pdfpc 302 | 303 | # sagetex 304 | *.sagetex.sage 305 | *.sagetex.py 306 | *.sagetex.scmd 307 | 308 | # scrwfile 309 | *.wrt 310 | 311 | # sympy 312 | *.sout 313 | *.sympy 314 | sympy-plots-for-*.tex/ 315 | 316 | # pdfcomment 317 | *.upa 318 | *.upb 319 | 320 | # pythontex 321 | *.pytxcode 322 | pythontex-files-*/ 323 | 324 | # thmtools 325 | *.loe 326 | 327 | # TikZ & PGF 328 | *.dpth 329 | *.md5 330 | *.auxlock 331 | 332 | # todonotes 333 | *.tdo 334 | 335 | # easy-todo 336 | *.lod 337 | 338 | # xmpincl 339 | *.xmpi 340 | 341 | # xindy 342 | *.xdy 343 | 344 | # xypic precompiled matrices 345 | *.xyc 346 | 347 | # endfloat 348 | *.ttt 349 | *.fff 350 | 351 | # Latexian 352 | TSWLatexianTemp* 353 | 354 | ## Editors: 355 | # WinEdt 356 | *.bak 357 | *.sav 358 | 359 | # Texpad 360 | .texpadtmp 361 | 362 | # LyX 363 | *.lyx~ 364 | 365 | # Kile 366 | *.backup 367 | 368 | # KBibTeX 369 | *~[0-9]* 370 | 371 | # auto folder when using emacs and auctex 372 | ./auto/* 373 | *.el 374 | 375 | # expex forward references with \gathertags 376 | *-tags.tex 377 | 378 | # standalone packages 379 | *.sta 380 | 381 | 382 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS := $(sort $(dir $(wildcard samples/*/*))) 2 | NAME = tikz-flowchart 3 | 4 | .PHONY: all $(SUBDIRS) clean 5 | 6 | all: $(SUBDIRS) 7 | xelatex $(NAME).ins 8 | xelatex --shell-escape --interaction=nonstopmode $(NAME).dtx 9 | xelatex --shell-escape --interaction=nonstopmode $(NAME).dtx 10 | makeindex -s gglo.ist -o $(NAME).gls $(NAME).glo 11 | xelatex --shell-escape --interaction=nonstopmode $(NAME).dtx 12 | xelatex --shell-escape --interaction=nonstopmode $(NAME).dtx 13 | 14 | $(SUBDIRS): ; $(MAKE) -C $@ $(MAKECMDGOALS) 15 | 16 | clean: $(SUBDIRS) 17 | --@rm -rf *.aux *.glo *.gls *.ilg *.log *.out *.toc 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tikz-flowchat 2 | 3 | ## 简介 4 | 这是一个使用TiKZ绘制传统程序流程图的简单宏包,通过定义`proc`、`test`、`io`、`term`等`node`样式实现。该宏包核心代码摘录自[Brent Longborough](http://www.texample.net/tikz/examples/author/brent-longborough/)设计的流程图绘制样例,参考了tikz-imagelabels宏包的设计思路,提供了`\flowchartset`命令以设置绘制参数。 5 | 6 | Happy LaTeXing!~ 7 | 8 | ![](./screenshot/flowchart01.png) 9 | ![](./screenshot/flowchart02.png) 10 | 11 | 更多示例,可以参考`demo.tex`文件。 12 | 13 | ## 编译宏包及宏包说明 14 | 如果没有`tikz-flowchart.sty`宏包文件,则可以在命令行通过运行`make`命令编译`tikz-flowchart.dtx`文件(需要有对应tikz-flowchart.ins文件)生成: 15 | * `tikz-flowchart.sty`宏包文件。 16 | * `tikz-flowchart.pdf`宏包说明文件。 17 | 18 | ## 使用方法 19 | 1. `\flowchartset`命令 20 | `\flowchartset`命令用于设置绘制参数,详细说明如下: 21 | 22 | ``` 23 | % 各绘图参数及其默认值 24 | \flowchartset{ 25 | free color = green, % 自由连线颜色(默认取green) 26 | norm color = blue, % 常规连线颜色(默认取blue) 27 | cong color = red, % 关联连线颜色(默认取red) 28 | proc fill color = white, % 顺序处理框填充颜色(默认取白色) 29 | test fill color = white, % 判断框填充颜色(默认取白色) 30 | io fill color = white, % 输入/输出框填充颜色(默认取白色) 31 | term fill color = white, % 开始/结束框填充颜色(默认取白色) 32 | proc text width = 8em, % 顺序处理框宽度(默认取8em) 33 | test text width = 5em, % 判断框宽度(默认取5em) 34 | io text width = 6em, % 输入/输出框宽度(默认取6em) 35 | term text width = 3em, % 开始/结束宽度(默认取3em) 36 | chain direction = below, % 结点自动布置方向(默认取below) 37 | minimum node distance = 6mm, % 最小结点间距(默认取6mm) 38 | maximum node distance = 60mm, % 最大结点间距(默认取60mm) 39 | border line width = \pgflinewidth, % 各类流程框边框宽度(默认取当前线条宽度) 40 | flow line width = \pgflinewidth, % 各类流程线线条宽度(默认取当前线条宽度) 41 | stealth length = 1.5mm, % 箭头长度(默认取1.5mm) 42 | stealth width = 1.0mm, % 箭头宽度(默认取1.0mm) 43 | } 44 | 45 | ``` 46 | 该命令允许仅指定需要的参数,可以放在导言区进行全局设置,也可以根据需要放在需要的地方进行局部设置。 47 | 48 | 2. 在`tikzpicture`环境中使用类似`\node [proc, join] (p1) {$k -= 1$};`的命令采用`proc`、`test`、`io`或`term`node样式参数布置需要的流程框结点。布置结点时,如果前一个结点不是`test`样式,则可以在`\node`命令中采用`join`参数自动与前一个结点建立连接并绘制流程线。可以根据需要对布置的结点进行命名,以便后续结点或连接点进行引用。*注意*:可以在`\node`命令中使用其它所有合法的参数。 49 | 50 | 3. 在`tikzpicture`环境中使用类似`\node [coord, right=0.8 of t1] (c1) {}; \cmark{1}`命令采用`coord`node样式布置其它需要的坐标点(用于流程线的转接)。同时,可以用`\cmark`命令为该点作出标记,以方便流程线连线调试。该标记在使用`debug`可选参数引入`\usepackage[debug]{tikz-flowchart}`宏包时,将进行绘制,若引入宏包时无`debug`可选参数,则不绘制该标记点。*注意*:可以在`\node`命令中使用其它所有合法的参数。 51 | 52 | 4. 在`tikzpicture`环境中使用类似`\path (t1.south) to node [near start, xshift=1em] {$y$} (p2);`命令进行流程线条件标注,再使用类似`\draw [norm] (t1.south) -- (p2);`命令,用`norm`、`free`或 `cong`draw样式绘制指定颜色的带有箭头的流程线。建议先绘制南北方向流程线,再绘制东西方向流程线。*注意*:可以在`\path`、`\draw`命令中使用其它所有合法的参数。 53 | 54 | 5. 在`tikzpicture`环境中使用其它各类合法TiKZ命令绘制需要的图形。 55 | 56 | 6. 该宏包还定义了`lnorm`、`lfree`和`lcong`draw样式,分别用于绘制指定颜色的无箭头的流程线;`dotnorm`、`dotfree`和`dotcong`draw样式,分别用于绘制指定颜色的实心交点;`cdotnorm`、`cdotfree`和`cdotcong`draw样式,分别用于绘制指定颜色的空心交点;`connector`draw样式,用于绘制流程线链接标记;`connect`draw样式,用于绘制非相交交汇流程线。 57 | 58 | 7. 更多绘制样例请参阅demo.tex文件中的样例代码及注释说明。 59 | 60 | ## 注意 61 | 62 | 1. 本文档要求 TeXLive、MacTeX、MikTeX 不低于 2018 年的发行版,并且尽可能升级到最新,强烈建议使用TeXLive2019。 63 | 64 | 2. **不支持** [CTeX 套装](http://www.ctex.org/CTeXDownload)。 65 | -------------------------------------------------------------------------------- /demo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/registor/tikz-flowchart/31152c9c7d957d84ebe7f440c27e65e47327e7b9/demo.pdf -------------------------------------------------------------------------------- /demo.tex: -------------------------------------------------------------------------------- 1 | % 使用ctexart文档类(用XeLaTeX编译,直接支持中文) 2 | \documentclass{ctexart} 3 | 4 | %导言区,可以在此引入必要的宏包 5 | \usepackage{tikz-flowchart} 6 | 7 | % 各参数默认值 8 | \flowchartset{ 9 | free color = green, % 自由连线颜色(默认取green) 10 | norm color = blue, % 常规连线颜色(默认取blue) 11 | cong color = red, % 关联连线颜色(默认取red) 12 | proc fill color = white, % 顺序处理框填充颜色(默认取白色) 13 | test fill color = white, % 判断框填充颜色(默认取白色) 14 | io fill color = white, % 输入/输出框填充颜色(默认取白色) 15 | term fill color = white, % 开始/结束框填充颜色(默认取白色) 16 | proc text width = 8em, % 顺序处理框宽度(默认取8em) 17 | test text width = 5em, % 判断框宽度(默认取5em) 18 | io text width = 6em, % 输入/输出框宽度(默认取6em) 19 | term text width = 3em, % 开始/结束宽度(默认取3em) 20 | chain direction = below, % 结点自动布置方向(默认取below) 21 | minimum node distance = 6mm, % 最小结点间距(默认取6mm) 22 | maximum node distance = 60mm, % 最大结点间距(默认取60mm) 23 | border line width = \pgflinewidth, % 各类流程框边框宽度(默认取当前线条宽度) 24 | flow line width = \pgflinewidth, % 各类流程线线条宽度(默认取当前线条宽度) 25 | stealth length = 1.5mm, % 箭头长度(默认取1.5mm) 26 | stealth width = 1.0mm, % 箭头宽度(默认取1.0mm) 27 | } 28 | 29 | \begin{document} %在document环境中撰写文档 30 | % 可以绘制复杂流程图 31 | \begin{tikzpicture} 32 | % ------------------------------------------------- 33 | % 布置结点单元 34 | \node [proc, densely dotted, it] (p0) {新触发器消息线程}; 35 | % 使用"join"参数以将新结点自动连接到前一个结点 36 | \node [term, join] {触发器调度表}; 37 | \node [proc, join] (p1) {获取配额 $k > 1$}; 38 | \node [proc, join] {打开队列}; 39 | \node [proc, join] {派发消息}; 40 | \node [test, join] (t1) {获得消息?}; 41 | % test结点的出口连接相对复杂,不再使用"join"参数 42 | % 继续布置完成所有结点 43 | \node [proc] (p2) {$k \mathbin{{-}{=}} 1$}; 44 | \node [proc, join] (p3) {派发消息}; 45 | \node [test, join] (t2) {获得消息?}; 46 | \node [test] (t3) {容量满?}; 47 | \node [test] (t4) {$k \mathbin{{-}{=}} 1$}; 48 | % 将下一个结点布置到第2栏,直接布置于p1结点的右边 49 | % 由于栏间距已进行设置,在此无需再次设定 50 | \node [proc, fill=\freecolor!25, right=of p1] (p4) {重置拥塞}; 51 | \node [proc, join=by free] {设置等待标志\textsc{mq}}; 52 | \node [proc, join=by free] (p5) {派发消息}; 53 | \node [test, join=by free] (t5) {获得消息?}; 54 | \node [test] (t6) {容量满?}; 55 | % 布置更多结点(应该避免这样布置结点,不是很好看) 56 | \node [test] (t7) [right=of t2] {$k \mathbin{{-}{=}} 1$}; 57 | \node [proc, fill=\congcolor!25, right=of t3] (p8) {设置拥塞}; 58 | \node [proc, join=by cong, right=of t4] (p9) {关闭队列}; 59 | \node [term, join] (p10) {退出触发器消息线程}; 60 | % ------------------------------------------------- 61 | % 布置坐标点,以实现拐角连接或添加注释说明 62 | % 同时,用\cmark命令对各个点进行了标记,以方便调试 63 | \node [coord, right=0.8 of t1] (c1) {}; \cmark{1} 64 | \node [coord, right=0.8 of t3] (c3) {}; \cmark{3} 65 | \node [coord, right=0.8 of t6] (c6) {}; \cmark{6} 66 | \node [coord, right=0.8 of t7] (c7) {}; \cmark{7} 67 | \node [coord, left=0.8 of t4] (c4) {}; \cmark{4} 68 | \node [coord, right=0.8 of t4] (c4r) {}; \cmark[r]{4} 69 | \node [coord, left=0.8 of t7] (c5) {}; \cmark{5} 70 | % ------------------------------------------------- 71 | % 布置注释结点 72 | \node [above=0mm of p4, it] {(队列为空)}; 73 | \node [above=0mm of p8, it] {(队列非空)}; 74 | % ------------------------------------------------- 75 | % 首先绘制判断框与其它结点单元南北方向的连接线 76 | % 每次绘制时,先绘制一个带有一个固定位置标注的路径(path) 77 | % 然后再绘制箭头本身(arrow)。 78 | \path (t1.south) to node [near start, xshift=1em] {$y$} (p2); 79 | \draw [norm] (t1.south) -- (p2); 80 | \path (t2.south) to node [near start, xshift=1em] {$y$} (t3); 81 | \draw [norm] (t2.south) -- (t3); 82 | \path (t3.south) to node [near start, xshift=1em] {$y$} (t4); 83 | \draw [norm] (t3.south) -- (t4); 84 | \path (t5.south) to node [near start, xshift=1em] {$y$} (t6); 85 | \draw [free] (t5.south) -- (t6); 86 | \path (t6.south) to node [near start, xshift=1em] {$y$} (t7); 87 | \draw [free] (t6.south) -- (t7); 88 | % ------------------------------------------------- 89 | % 其次绘制判断框与其它结点单元东西方向的连接线 90 | % 为固定标位置,在垂直方向上进行坐标设定,然后再绘制箭头本身(arrow)。 91 | \path (t3.east) to node [near start, yshift=1em] {$n$} (c3); 92 | \draw [cong] (t3.east) -- (p8); 93 | \path (t4.east) to node [yshift=-1em] {$k \leq 0$} (c4r); 94 | \draw [norm] (t4.east) -- (p9); 95 | % ------------------------------------------------- 96 | % 最后绘制其它方向的连接线 97 | % 同样先绘制一个带有一个固定位置标注的路径(path),然后再绘制箭头本身(arrow)。 98 | \path (t1.east) to node [near start, yshift=1em] {$n$} (c1); 99 | \draw [free] (t1.east) -- (c1) |- (p4); 100 | \path (t2.east) -| node [very near start, yshift=1em] {$n$} (c1); 101 | \draw [free] (t2.east) -| (c1); 102 | \path (t4.west) to node [yshift=-1em] {$k>0$} (c4); 103 | \draw [norm] (t4.west) -- (c4) |- (p3); 104 | \path (t5.east) -| node [very near start, yshift=1em] {$n$} (c6); 105 | \draw [free] (t5.east) -| (c6); 106 | \path (t6.east) to node [near start, yshift=1em] {$n$} (c6); 107 | \draw [free] (t6.east) -| (c7); 108 | \path (t7.east) to node [yshift=-1em] {$k \leq 0$} (c7); 109 | \draw [free] (t7.east) -- (c7) |- (p9); 110 | \path (t7.west) to node [yshift=-1em] {$k>0$} (c5); 111 | \draw [free] (t7.west) -- (c5) |- (p5); 112 | % ------------------------------------------------- 113 | % 最后一个标不符合以上所有规则 114 | \draw [->, dotted, thick, shorten >=1mm] 115 | (p9.south) -- ++(5mm,-3mm) -- ++(27mm,0) 116 | |- node [black, near end, yshift=0.75em, it] 117 | {(当消息和资源都有效时)} (p0); 118 | % ------------------------------------------------- 119 | \end{tikzpicture} 120 | 121 | % 可以在结点中使用\verb等命令 122 | \begin{tikzpicture} 123 | % 布置结点单元 124 | \node [term] (st) {开始}; 125 | \node [proc, join] (p1) {\verb!int r = 0!}; 126 | \node [test, join] (t1) {\verb!m < n!}; 127 | \node [proc] (p2) {\verb! m ^= n !\\ \verb!n ^= m !\\ \verb!m ^= n!}; 128 | \node [test, join] (t2) {\verb|n != 0|}; 129 | \node [proc] (p3) {\verb!r = m % n! \\ \verb!m = n!\\ \verb!n = r!}; 130 | \node [proc] (p4) {\verb!return m!}; 131 | \node [term, join] (end) {结束}; 132 | 133 | % 布置用于连接的坐标结点,同时为其布置调试标记点。 134 | \node [coord] (c1) at ($(p2.south)!0.5!(t2.north)$) {}; \cmark{1} 135 | \node [coord, below = 0.25 of p3] (c2) {}; \cmark{2} 136 | \node [coord, above = 0.25 of p4] (c3) {}; \cmark{3} 137 | \node [coord, right = 1.0 of t1] (c4) {}; \cmark{4} 138 | \node [coord, right = 1.0 of t2] (c5) {}; \cmark{5} 139 | \node [coord, left = 1.0 of t2] (ct) {}; \cmark{t} 140 | \node [coord] (c6) at (ct |- c2) {}; \cmark{6} 141 | 142 | % 判断框连线,每次绘制时,先绘制一个带有一个固定 143 | % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 144 | \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 145 | \draw [norm] (t1.south) -- (p2.north); 146 | \path (t1.east) -- node [near start, above] {$N$} (c4); 147 | \draw [norm] (t1.east) -- (c4) |- (c1); 148 | \path (t2.south) -- node [near start, right] {$Y$} (p3.north); 149 | \draw [norm] (t2.south) -- (p3.north); 150 | \path (t2.east) -- node [near start, above] {$N$} (c5); 151 | \draw [norm] (t2.east) -- (c5) |- (c3) -- (p4.north); 152 | 153 | % 其它连线 154 | \draw [norm](p3.south) |- (c6) |- (c1); 155 | \end{tikzpicture} 156 | 157 | % 可以更改字号、各类流程框的宽度等 158 | \begin{tikzpicture}[font=\small] 159 | % 布置结点单元 160 | \node [term] (st) {开始}; 161 | \node [proc, join] (p1) {\verb|sum = x|\\\verb|x_pow = x|\\\verb|item = 0.0|}; 162 | \node [proc, join] (p2) {\verb|n = 1|\\\verb|fact = 1|\\\verb|sign = 1|}; 163 | \node [proc, join, text width = 16em] (p3) {\verb|fact = fact * (n + 1) * (n + 2)|\\\verb|x_pow *= x * x|\\\verb|sign = -sign|\\\verb|item = sign * x_pow / fact|\\\verb|sum += item|\\\verb|n += 2|}; 164 | 165 | \node [test, join, text width = 10em] (t1) {\verb|fabs(item) > epsilon|}; 166 | \node [proc] (p4) {\verb|return sum|}; 167 | \node [term, join] (end) {结束}; 168 | 169 | % 布置用于连接的坐标结点,同时为其布置调试标记点。 170 | \node [coord] (c1) at ($(p2.south)!0.5!(p3.north)$) {}; \cmark{1} 171 | \node [coord, right = 2.0 of t1] (ct) {}; \cmark{t} 172 | \node [coord] (c2) at (ct |- c1) {}; \cmark{2} 173 | 174 | % 判断框连线,每次绘制时,先绘制一个带有一个固定 175 | % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 176 | \path (t1.south) -- node [near start, right] {$N$} (p4.north); 177 | \draw [norm] (t1.south) -- (p4.north); 178 | \path (t1.east) -- node [near start, above] {$Y$} (ct); 179 | \draw [norm] (t1.east) -| (c2) -- (c1); 180 | \end{tikzpicture} 181 | 182 | % 可以局部更改各参数 183 | \flowchartset{ 184 | proc fill color = orange!10, % 顺序处理框填充颜色(默认取白色) 185 | test fill color = green!30, % 判断框填充颜色(默认取白色) 186 | io fill color = blue!30, % 输入/输出框填充颜色(默认取白色) 187 | term fill color = red!30, % 开始/结束框填充颜色(默认取白色) 188 | } 189 | 190 | \begin{tikzpicture} 191 | % 布置结点单元 192 | \node [term] (st) {开始}; 193 | \node [proc, text width = 6em, join] (p1) {\verb|int divisor|}; 194 | \node [test, join] (t1) {\verb|n <= 1|}; 195 | \node [proc, text width = 6em] (p2) {\verb|divisor = 2|}; 196 | \node [test, text width = 10em, join] (t2) {\verb|divisor * divisor <= n|}; 197 | \node [test, text width = 8em] (t3) {\verb|n % divisor == 0|}; 198 | \node [proc, text width = 6em] (p3) {\verb|divisor++|}; 199 | \node [term, below = 1.6 of p3] (end) {结束}; 200 | \node [proc, text width = 6em, left = 4.8 of t2] (p4) {\verb|return 0|}; 201 | \node [proc, text width = 6em, right = 3.5 of p3] (p5) {\verb|return 0|}; 202 | \node [proc, text width = 6em, right = 5.8 of t3] (p6) {\verb|return 1|}; 203 | 204 | % 布置用于连接的坐标结点,同时为其布置调试标记点。 205 | \node [coord] (c1) at ($(p2.south)!0.5!(t2.north)$) {}; \cmark{1} 206 | \node [coord, below = 0.25 of p3] (c2) {}; \cmark{2} 207 | \node [coord, above = 0.5 of end] (c3) {}; \cmark{3} 208 | \node [coord, left = 0.5 of t2] (ct) {}; \cmark{t} 209 | \node [coord] (c4) at (c3 -| p5) {}; \cmark{4} 210 | \node [coord] (c5) at (c2 -| ct) {}; \cmark{5} 211 | 212 | % 判断框连线,每次绘制时,先绘制一个带有一个固定 213 | % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 214 | \path (t1.south) -- node [near start, right] {$N$} (p2.north); 215 | \draw [norm] (t1.south) -- (p2.north); 216 | \path (t1.west) -| node [near start, above] {$Y$} (p4.north); 217 | \draw [norm] (t1.west) -| (p4.north); 218 | 219 | \path (t2.south) -- node [near start, right] {$Y$} (t3.north); 220 | \draw [norm] (t2.south) -- (t3.north); 221 | \path (t2.east) -| node [near start, above] {$N$} (p6.north); 222 | \draw [norm] (t2.east) -| (p6.north); 223 | 224 | \path (t3.south) -- node [near start, right] {$N$} (p3.north); 225 | \draw [norm] (t3.south) -- (p3.north); 226 | \path (t3.east) -| node [near start, above] {$Y$} (p5.north); 227 | \draw [norm] (t3.east) -| (p5.north); 228 | 229 | % 其它连线 230 | \draw [norm](p3.south) |- (c5) |- (c1); 231 | \draw [norm](p4.south) |- (c3); 232 | \draw [norm](p4.south) |- (c3) -- (end); 233 | \draw [norm](p5.south) -- (c4); 234 | \draw [norm](p6.south) |- (c3); 235 | \draw [norm](p6.south) |- (c3) -- (end); 236 | \end{tikzpicture} 237 | 238 | % 测试文字宽度及非连接交点 239 | % 各参数默认值 240 | \flowchartset{ 241 | proc text width = 4em, % 顺序处理框宽度(默认取8em) 242 | test text width = 3em, % 判断框宽度(默认取5em) 243 | } 244 | \begin{tikzpicture} 245 | % 布置结点单元 246 | \node [proc] (p1){\verb|d = 2|}; 247 | \node [test, join] (t1) {\verb|a < n|?}; 248 | \node [test] (t2) {\verb|n % d == 0|}; 249 | \node [proc] (p2) {\verb|d++|}; 250 | \node [proc,below = 1.5 of p2] (p3) {\verb|d = 2|}; 251 | \node [test, join] (t3) {\verb|d < n|?}; 252 | \node [proc, left = 2.0 of t3, shift={(0cm, -0.8cm)}] (p4) {\verb|z = d|}; 253 | \node [proc, right = 2.0 of t3, shift={(0cm, -0.8cm)}] (p5) {\verb|z = n|}; 254 | 255 | % 布置用于连接的坐标结点,同时为其布置调试标记点。 256 | \node [coord, above = 0.5 of p1] (c1) {};% \cmark{1} 257 | \node [coord] (c2) at ($(p1)!0.35!(t1)$) {};% \cmark{2} 258 | \node [coord, below = 0.25 of p2] (c3) {};% \cmark{3} 259 | \node [coord, above = 0.45 of p3] (c4) {};% \cmark{4} 260 | \node [coord] (c5) at ($(p3)!0.35!(t3)$) {};% \cmark{5} 261 | \node [coord, below = 0.5 of p4] (c6) {};% \cmark{6} 262 | \node [coord] (c7) at (c6 -| p4) {};% \cmark{7} 263 | \node [coord] (c8) at (c6 -| t3) {};% \cmark{8} 264 | \node [coord, right = 1.0 of t1] (c9) {};% \cmark{9} 265 | \node [coord] (c10) at (c9 |- t2) {};% \cmark{10} 266 | \node [coord, right = 0.5 of c10] (c11) {};% \cmark{11} 267 | \node [coord, left = 0.8 of t1] (ct) {};% \cmark{t} 268 | \node [coord] (c12) at (c3 -| ct) {};% \cmark{12} 269 | \node [coord, below = 0.5 of c8] (c13) {};% \cmark{13} 270 | 271 | % 判断框连线,每次绘制时,先绘制一个带有一个固定 272 | % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 273 | \path (t1.south) -- node [near start, right] {$Y$} (t2.north); 274 | \draw [norm] (t1.south) -- (t2.north); 275 | \path (t1.east) -- node [near start, above] {$N$} (c9); 276 | \draw [norm] (t1.east) -- (c9) |- (c4) -- (p3.north); 277 | 278 | \path (t2.south) -- node [near start, right] {$N$} (p2.north); 279 | \draw [norm] (t2.south) -- (p2.north); 280 | \path (t2.east) -- node [near start, above] {$Y$} (c10); 281 | \draw [lnorm] (t2.east) -- ($(c10) + (-2pt, 0)$); 282 | 283 | \path (t3.west) -| node [near start, above] {$Y$} (p4.north); 284 | \draw [norm] (t3.west) -| (p4.north); 285 | \path (t3.east) -| node [near start, above] {$N$} (p5.north); 286 | \draw [norm] (t3.east) -| (p5.north); 287 | 288 | % 其它连线 289 | \draw [norm] (c1) -- (p1); 290 | \draw [norm] (p2.south) |- (c12) |- (c2); 291 | % 绘制不相交的两个交汇路径,注意connect样式的使用 292 | \draw [norm, connect=(t2.east) to (c11) over (c10) by 3pt] |- (c5); 293 | \draw [norm] (p4.south) |- (c8) -- (c13); 294 | \draw [norm] (p5.south) |- (c8) -- (c13); 295 | \end{tikzpicture} 296 | 297 | \end{document} 298 | 299 | %%% Local Variables: 300 | %%% mode: latex 301 | %%% TeX-master: t 302 | %%% End: 303 | -------------------------------------------------------------------------------- /screenshot/flowchart01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/registor/tikz-flowchart/31152c9c7d957d84ebe7f440c27e65e47327e7b9/screenshot/flowchart01.png -------------------------------------------------------------------------------- /screenshot/flowchart02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/registor/tikz-flowchart/31152c9c7d957d84ebe7f440c27e65e47327e7b9/screenshot/flowchart02.png -------------------------------------------------------------------------------- /tikz-flowchart.dtx: -------------------------------------------------------------------------------- 1 | % \iffalse meta-comment 2 | % 3 | % Copyright (C) 2019 by Geng Nan 4 | % 5 | % This file may be distributed and/or modified under the 6 | % conditions of the LaTeX Project Public License, either 7 | % version 1.3 of this license or (at your option) any later 8 | % version. The latest version of this license is in: 9 | % 10 | % http://www.latex-project.org/lppl.txt 11 | % 12 | % and version 1.3 or later is part of all distributions of 13 | % LaTeX version 2005/12/01 or later. 14 | % 15 | % \fi 16 | % 17 | % \iffalse 18 | %\NeedsTeXFormat{LaTeX2e}[2011/06/27] 19 | %\ProvidesPackage{tikz-flowchart} 20 | % [2019/08/20 v1.0.01 draw flowchart using TikZ] 21 | % 22 | %<*driver> 23 | \documentclass[a4paper]{ltxdoc} 24 | \RecordChanges 25 | 26 | \usepackage[UTF8,scheme=chinese]{ctex} 27 | \usepackage{csquotes} 28 | \usepackage{lmodern} 29 | \usepackage{hyperref} 30 | \usepackage{url} 31 | \usepackage{amsmath} 32 | \usepackage{amssymb} 33 | \usepackage{dtxdescribe} 34 | \usepackage[debug]{tikz-flowchart} 35 | \usepackage{float} 36 | % \usepackage{parskip} 37 | 38 | \renewcommand\figureautorefname\figurename 39 | \renewcommand\tableautorefname\tablename 40 | 41 | % default position for floats: H 42 | \makeatletter 43 | \renewcommand{\fps@figure}{H} 44 | \renewcommand{\fps@table}{H} 45 | \makeatother 46 | 47 | %\setlength{\parindent}{0pt} 48 | 49 | \def\thispkg{\pkg{tikz-flowchart}} 50 | \def\tkz{Ti\emph{k}Z} 51 | 52 | \newcommand{\note}[2][注意]{{% 53 | \color{magenta}{\bfseries #1:}\emph{#2}}} 54 | \makeatletter 55 | \DeclareRobustCommand*\Arg[1]{\@meta{#1}} 56 | \def\@meta#1{$\m@th\langle$\textnormal{\textit{#1}}$\m@th\rangle$} 57 | \makeatother 58 | 59 | \begin{document} 60 | \DocInput{tikz-flowchart.dtx} 61 | \end{document} 62 | % 63 | % \fi 64 | % 65 | % \CheckSum{0} 66 | % 67 | % \CharacterTable 68 | % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z 69 | % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z 70 | % Digits \0\1\2\3\4\5\6\7\8\9 71 | % Exclamation \! Double quote \" Hash (number) \# 72 | % Dollar \$ Percent \% Ampersand \& 73 | % Acute accent \' Left paren \( Right paren \) 74 | % Asterisk \* Plus \+ Comma \, 75 | % Minus \- Point \. Solidus \/ 76 | % Colon \: Semicolon \; Less than \< 77 | % Equals \= Greater than \> Question mark \? 78 | % Commercial at \@ Left bracket \[ Backslash \\ 79 | % Right bracket \] Circumflex \^ Underscore \_ 80 | % Grave accent \` Left brace \{ Vertical bar \| 81 | % Right brace \} Tilde \~} 82 | % 83 | % \changes{v1.0.01}{2019/08/20}{chang .sty file to .dtx file} 84 | % 85 | % \GetFileInfo{tikz-flowchart.sty} 86 | % 87 | % \title{\thispkg{}---\tkz{}流程图绘制宏包\thanks{该文档是 \thispkg{}~\fileversion, dated~\filedate 的说明文档。}} 88 | % \author{耿楠\thanks{https://github.com/registor/tikz-flowchart}\\ 西北农林科技大学信息工程学院计算机科学系} 89 | % \date{\filedate} 90 | % \thispagestyle{empty} 91 | % \maketitle 92 | % 93 | % \begin{abstract} 94 | % 这是一个使用\tkz{}绘制传统程序流程图的简单宏包,通过定义 95 | % \Arg{proc}、\Arg{test}、\Arg{io}、\Arg{term}等\tkz{}的 96 | % \cs{node}命令的样式选项实现。 97 | % 该宏包核心代码摘录自\href{http://www.texample.net/tikz/examples/author/brent-longborough/}{Brent Longborough}设计的流程图绘制样例, 98 | % 参考了\pkg{tikz-imagelabels}宏包的设计思路,提供了\cs{flowchartset}命令以设置绘制参数。 99 | % \end{abstract} 100 | % 101 | % \tableofcontents 102 | % 103 | % \PrintChanges 104 | % 105 | % \StopEventually{} 106 | % 107 | % \section{宏包简介} 108 | % 109 | % 流程图是诸如手册、报告、论文等文档中经常用到的排版元素,\thispkg{}宏包的 110 | % 目的是为在\LaTeX{}中使用\tkz{}绘制流程图提供方便。\autoref{fig:forloop}是使 111 | % 用该宏包绘制|for|循环结构流程图的一个简单示例。 112 | % 113 | % \begin{figure}[!htp] 114 | % \centering 115 | % \begin{tikzpicture} 116 | % \node [proc] (p1) {表达式1}; 117 | % \node [test, join] (t1) {表达式2?}; 118 | % \node [proc] (p2) {循环体}; 119 | % \node [proc, join] (p3) {表达式3}; 120 | % 121 | % \node [coord, above = 0.5 of p1] (c1) {}; 122 | % \node [coord] (c2) at ($(p1)!0.35!(t1)$) {}; 123 | % \node [coord, below = 0.25 of p3] (c3) {}; 124 | % \node [coord, below = 0.2 of c3] (c4) {}; 125 | % \node [coord, below = 0.5 of c4] (c5) {}; 126 | % \node [coord, right = 0.5 of t1] (c6) {}; 127 | % \node [coord, left = 0.5 of t1] (ct) {}; 128 | % \node [coord] (c7) at (c3 -| ct) {}; 129 | % 130 | % \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 131 | % \draw [norm] (t1.south) -- (p2.north); 132 | % \path (t1.east) -- node [near start, above] {$N$} (c6); 133 | % \draw [norm] (t1.east) -- (c6) |- (c4) -- (c5); 134 | % 135 | % \draw [norm] (c1) -- (p1); 136 | % \draw [norm] (p3.south) |- (c7) |- (c2); 137 | % \end{tikzpicture} 138 | % \caption{for循环流程图} 139 | % \label{fig:forloop} 140 | % \end{figure} 141 | % 142 | % \autoref{fig:forloop}由如下代码绘制: 143 | % \begin{sourceverb} 144 | % \begin{tikzpicture} 145 | % % 布置结点 146 | % \node [proc] (p1) {表达式1}; 147 | % \node [test, join] (t1) {表达式2?}; 148 | % \node [proc] (p2) {循环体}; 149 | % \node [proc, join] (p3) {表达式3}; 150 | % % 布置用于连接的坐标结点。 151 | % \node [coord, above = 0.5 of p1] (c1) {}; 152 | % \node [coord] (c2) at ($(p1)!0.35!(t1)$) {}; 153 | % \node [coord, below = 0.25 of p3] (c3) {}; 154 | % \node [coord, below = 0.2 of c3] (c4) {}; 155 | % \node [coord, below = 0.5 of c4] (c5) {}; 156 | % \node [coord, right = 0.5 of t1] (c6) {}; 157 | % \node [coord, left = 0.5 of t1] (ct) {}; 158 | % \node [coord] (c7) at (c3 -| ct) {}; 159 | % % 判断框连线,每次绘制时,先绘制一个带有一个固定 160 | % % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 161 | % \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 162 | % \draw [norm] (t1.south) -- (p2.north); 163 | % \path (t1.east) -- node [near start, above] {$N$} (c6); 164 | % \draw [norm] (t1.east) -- (c6) |- (c4) -- (c5); 165 | % % 其它连线 166 | % \draw [norm] (c1) -- (p1); 167 | % \draw [norm] (p3.south) |- (c7) |- (c2); 168 | % \end{tikzpicture} 169 | % \end{sourceverb} 170 | % 171 | % \note{所有绘图代码都需在\env{tikzpicture}环境中完成。} 172 | % \section{使用方法} 173 | % \subsection{载入宏包} 174 | % \DescribeOption[\thispkg{}]{debug} 175 | % 在导言区使用:\cs{usepackage}\oarg{debug}\marg{\thispkg{}}命令 176 | % 载入宏包。如果带有\oarg{debug}参数,则可以绘制用于调试的流程线转角点 177 | % 标记,否则,则不绘制该标记,\autoref{fig:forloopcmark}是带有 178 | % \oarg{debug}参数时的绘制结果。 179 | % 180 | % \begin{figure}[!htp] 181 | % \centering 182 | % \begin{tikzpicture} 183 | % \node [proc] (p1) {表达式1}; 184 | % \node [test, join] (t1) {表达式2?}; 185 | % \node [proc] (p2) {循环体}; 186 | % \node [proc, join] (p3) {表达式3}; 187 | % 188 | % \node [coord, above = 0.5 of p1] (c1) {}; \cmark{1} 189 | % \node [coord] (c2) at ($(p1)!0.35!(t1)$) {}; \cmark{2} 190 | % \node [coord, below = 0.25 of p3] (c3) {}; \cmark{3} 191 | % \node [coord, below = 0.2 of c3] (c4) {}; \cmark{4} 192 | % \node [coord, below = 0.5 of c4] (c5) {}; \cmark{5} 193 | % \node [coord, right = 0.5 of t1] (c6) {}; \cmark{6} 194 | % \node [coord, left = 0.5 of t1] (ct) {}; \cmark{t} 195 | % \node [coord] (c7) at (c3 -| ct) {}; \cmark{7} 196 | % 197 | % \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 198 | % \draw [norm] (t1.south) -- (p2.north); 199 | % \path (t1.east) -- node [near start, above] {$N$} (c6); 200 | % \draw [norm] (t1.east) -- (c6) |- (c4) -- (c5); 201 | % 202 | % \draw [norm] (c1) -- (p1); 203 | % \draw [norm] (p3.south) |- (c7) |- (c2); 204 | % \end{tikzpicture} 205 | % \caption{for循环流程图} 206 | % \label{fig:forloopcmark} 207 | % \end{figure} 208 | % 209 | % \subsection{流程图绘制样式} 210 | % \thispkg{}宏包定义了在\tkz{}中绘制流程图的绘图样式参数,以简化绘图过程。 211 | % 212 | % \begin{description} 213 | % \ItemDescribeArgument[\cs{node}]{proc}\cs{node}命令绘制顺序执行框 214 | % 的样式,如:\tikz{\node[proc]{\scriptsize 交换两个整数}} 215 | % \ItemDescribeArgument[\cs{node}]{test}\cs{node}命令绘制判断框的样 216 | % 式,如:\tikz{\node[test, minimum height=1ex]{\scriptsize $a > b$?}} 217 | % \ItemDescribeArgument[\cs{node}]{io}\cs{node}命令绘制输入/输出框 218 | % 的样式,如:\tikz{\node[io]{\scriptsize 输入两个整数}} 219 | % \ItemDescribeArgument[\cs{node}]{term}\cs{node}命令绘制开始/结束 220 | % 框的样式,如:\tikz{\node[term]{\scriptsize 开始}} 221 | % \ItemDescribeArgument[\cs{node}]{it}\cs{node}命令绘制斜体标注 222 | % 的样式,如:\tikz{\node[it]{\scriptsize 这里需要特别注意}} 223 | % \ItemDescribeArgument[\cs{node}]{connector}\cs{node}命令绘制流程 224 | % 图链接点的样式,如:\tikz{\node[connector]{\scriptsize 1}} 225 | % \ItemDescribeArgument[\cs{node}]{coord}\cs{node}命令布置转角结点 226 | % 的样式,如:\tikz{\node[coord](c1){};\cmark{1}} 227 | % \ItemDescribeArgument[\cs{draw}]{connect}\cs{draw}命令绘制不相交 228 | % 的两个交汇路径的样式,如:\tikz{\node[coord](c1)at(0,0){}; 229 | % \node[coord](c2)at(0.3,0){};\node[coord](c3)at(0.15,-0.15){}; 230 | % \node[coord](c4)at(0.15,0.15){};\node[coord] (c5) at (c4 |- c1) 231 | % {};\draw[lnorm](c3)--(c4); 232 | % \draw[lnorm, connect=(c1) to (c2) over (c5) by 1.5pt] -- (c2);} 233 | % \ItemDescribeArgument[\cs{draw}]{lnorm}\cs{draw}命令绘制指定颜色 234 | % 无箭头连线的样式,如:\tikz{\draw[lnorm](0,0)--(0.5,0)} 235 | % \ItemDescribeArgument[\cs{draw}]{lfree}\cs{draw}命令绘制指定颜色 236 | % 无箭头连线的样式,如:\tikz{\draw[lfree](0,0)--(0.5,0)} 237 | % \ItemDescribeArgument[\cs{draw}]{lcong}\cs{draw}命令绘制指定颜色 238 | % 无箭头连线的样式,如:\tikz{\draw[lcong](0,0)--(0.5,0)} 239 | % \ItemDescribeArgument[\cs{draw}]{norm}\cs{draw}命令绘制指定颜色箭 240 | % 头连线的样式,如:\tikz{\draw[norm](0,0)--(0.5,0)} 241 | % \ItemDescribeArgument[\cs{draw}]{free}\cs{draw}命令绘制指定颜色箭 242 | % 头连线的样式,如:\tikz{\draw[free](0,0)--(0.5,0)} 243 | % \ItemDescribeArgument[\cs{draw}]{dotnorm}\cs{draw}命令绘制指定颜 244 | % 色流程线实心交点的样式,如:\tikz{\draw[dotnorm](0,0) circle(1.5pt)} 245 | % \ItemDescribeArgument[\cs{draw}]{dotfree}\cs{draw}命令绘制指定颜 246 | % 色流程线实心交点的样式,如:\tikz{\draw[dotfree](0,0) circle(1.5pt)} 247 | % \ItemDescribeArgument[\cs{draw}]{dotcong}\cs{draw}命令绘制指定颜 248 | % 色流程线实心交点的样式,如:\tikz{\draw[dotcong](0,0) circle(1.5pt)} 249 | % \ItemDescribeArgument[\cs{draw}]{cdotnorm}\cs{draw}命令绘制指定颜 250 | % 色流程线空心交点的样式,如:\tikz{\draw[cdotnorm](0,0) circle(1.5pt)} 251 | % \ItemDescribeArgument[\cs{draw}]{cdotfree}\cs{draw}命令绘制指定颜 252 | % 色流程线空心交点的样式,如:\tikz{\draw[cdotfree](0,0) circle(1.5pt)} 253 | % \ItemDescribeArgument[\cs{draw}]{cdotcong}\cs{draw}命令绘制指定颜 254 | % 色流程线空心交点的样式,如:\tikz{\draw[cdotcong](0,0) circle(1.5pt)} 255 | % \end{description} 256 | % 257 | % \subsection{样式参数设置命令} 258 | % \DescribeMacro{\flowchartset} 259 | % \thispkg{}宏包定义了\cs{flowchartset}命令,该命令用于设置流程图各元 260 | % 素的绘制属性,详情见如下代码注释。 261 | % 262 | % \begin{sourceverb}[xleftmargin=0em] 263 | % \flowchartset{ 264 | % free color = green, % 自由连线颜色(默认取green) 265 | % norm color = blue, % 常规连线颜色(默认取blue) 266 | % cong color = red, % 关联连线颜色(默认取red) 267 | % proc fill color = white, % 顺序处理框填充颜色(默认取白色) 268 | % test fill color = white, % 判断框填充颜色(默认取白色) 269 | % io fill color = white, % 输入/输出框填充颜色(默认取白色) 270 | % term fill color = white, % 开始/结束框填充颜色(默认取白色) 271 | % proc text width = 8em, % 顺序处理框宽度(默认取8em) 272 | % test text width = 5em, % 判断框宽度(默认取5em) 273 | % io text width = 6em, % 输入/输出框宽度(默认取6em) 274 | % term text width = 3em, % 开始/结束宽度(默认取3em) 275 | % chain direction = below, % 结点自动布置方向(默认取below) 276 | % minimum node distance = 6mm, % 最小结点间距(默认取6mm) 277 | % maximum node distance = 60mm, % 最大结点间距(默认取60mm) 278 | % border line width = \pgflinewidth, % 流程框边框宽度(默认取当前线条宽度) 279 | % flow line width = \pgflinewidth, % 流程线线条宽度(默认取当前线条宽度) 280 | % stealth length = 1.5mm, % 箭头长度(默认取1.5mm) 281 | % stealth width = 1.0mm, % 箭头宽度(默认取1.0mm) 282 | % } 283 | % \end{sourceverb} 284 | % 285 | % 这些参数设置方式与常规的\tkz{}参数设置类似,即可以多个参数一起设置, 286 | % 也可以分开单独设置。\cs{flowchartset}命令可以在导言区进行全局设置, 287 | % 也可以在需要的位置进行局部设置。 288 | % \section{流程图绘制步骤} 289 | % \subsection{布置流程框结点} 290 | % 使用类似``|\node [proc](p1){表达式1};|''命令,采用\thispkg{} 291 | % 定义的``|proc|''、``|test|''、``|io|''或``|term|''样式参数布置需要的流程框结点。 292 | % 293 | % 294 | % 在布置结点时,如果前一个结点不是``|test|''样式,则可以使用 295 | % ``|join|''参数自动与前一个结点建立连接,如 296 | % ``|\node [proc, join] (p3) {表达式3};|'',并同时绘制对应流程线。 297 | % 298 | % 另外,可根据需要对结点进行命名(如``|p1|''、 299 | % ``|t1|''等),以便引用该结点。 300 | % 301 | % \subsection{布置坐标点} 302 | % 使用类似``|\node[coord,above=0.5 of p1](c1){};\cmark{1}|'' 303 | % 命令,用``|coord|''样式参数布置其它坐标点 304 | % (主要用于流程线的转接)。同时,可以使用``\cs{cmark}''命令为该点作标 305 | % 记,在带\oarg{debug}可选参数引入 306 | % 宏包时,则绘制标记点,若无\oarg{debug}参数,则不绘制标记点。 307 | % 308 | % \subsection{绘制流程线} 309 | % 首先使用类似``|\path(t1.south)--node[near start,right]{$Y$}(p2.north);|'' 310 | % 的路径命令绘制流程线的标注文字。 311 | % 312 | % 然后使用类似``\verb!\draw[norm](t1.east)--(c6)|-(c4)--(c5);!'' 313 | % 绘制命令绘制带有箭头的流程线。 314 | % 315 | % 可以使用``|lnorm|''、``|lfree|''或 316 | % ``|lcong|''绘制指定颜色的无箭头流程线,用``|norm|''、 317 | % ``|free|''或``|cong|''绘制指定颜色的有箭头流程线。 318 | % 319 | % \note[建议]{先绘制南北方向流程线,再绘制东西方向流程线}。 320 | % 321 | % 可以使用``|dotnorm|''、``|dotfree|''和 322 | % ``|dotcong|''样式绘制流程线实心交点,用``|cdotnorm|''、 323 | % ``|cdotfree|''或``|cdotcong|''样式绘制流程线空心交点。 324 | % 325 | % 对于不相交的流程线,可以用``|connect|''样式进行绘制。 326 | % 327 | % \subsection{绘制其它图形} 328 | % 在使用\cs{node}、\cs{path}、\cs{draw}等命令时,可以同时使用任何 329 | % 合法的\tkz{}参数,同时,也可以使用任何合法\tkz{}命令绘制需要的其它图形。 330 | % 331 | % \section{改变绘图属性} 332 | % 333 | % \subsection{改变流程线颜色} 334 | % 通过在导言区使用\cs{flowchartset}命令可以全局设置需要的绘图属性, 335 | % 如: 336 | % \begin{sourceverb} 337 | % \usepackage{tikz-flowchart} 338 | % \flowchartset{ 339 | % norm color = black, % 将常规连线颜色设置为black 340 | % } 341 | % ...... 342 | % \end{sourceverb} 343 | % 344 | % \note{可以多次使用\cs{flowchartset}命令,每次可仅指定需要的参数。} 345 | % 346 | % 例如,仅指定``\verb|norm|''类型的颜色为``\verb|black|'',得到 347 | % \autoref{fig:forloopblack}所示的黑色流程线。 348 | % 349 | % \flowchartset{ 350 | % norm color = black, 351 | % } 352 | % 353 | % \begin{figure}[!htp] 354 | % \centering 355 | % \begin{tikzpicture} 356 | % \node [proc] (p1) {表达式1}; 357 | % \node [test, join] (t1) {表达式2?}; 358 | % \node [proc] (p2) {循环体}; 359 | % \node [proc, join] (p3) {表达式3}; 360 | % 361 | % \node [coord, above = 0.5 of p1] (c1) {}; 362 | % \node [coord] (c2) at ($(p1)!0.35!(t1)$) {}; 363 | % \node [coord, below = 0.25 of p3] (c3) {}; 364 | % \node [coord, below = 0.2 of c3] (c4) {}; 365 | % \node [coord, below = 0.5 of c4] (c5) {}; 366 | % \node [coord, right = 0.5 of t1] (c6) {}; 367 | % \node [coord, left = 0.5 of t1] (ct) {}; 368 | % \node [coord] (c7) at (c3 -| ct) {}; 369 | % 370 | % \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 371 | % \draw [norm] (t1.south) -- (p2.north); 372 | % \path (t1.east) -- node [near start, above] {$N$} (c6); 373 | % \draw [norm] (t1.east) -- (c6) |- (c4) -- (c5); 374 | % 375 | % \draw [norm] (c1) -- (p1); 376 | % \draw [norm] (p3.south) |- (c7) |- (c2); 377 | % \end{tikzpicture} 378 | % \caption{黑色流程线流程图} 379 | % \label{fig:forloopblack} 380 | % \end{figure} 381 | % 382 | % \subsection{改变流程框填充色和宽度} 383 | % 也可以在需要时用\cs{flowchartset}命令进行绘图属性的局部设置。 384 | % 如,可以用如下代码局部改变各类流程框的填充颜色和文字宽度: 385 | % \begin{sourceverb} 386 | % \flowchartset{ 387 | % proc fill color = orange!10, 388 | % test fill color = green!30, 389 | % io fill color = blue!30, 390 | % term fill color = red!30, 391 | % proc text width = 6em, 392 | % test text width = 5em, 393 | % } 394 | % \begin{tikzpicture} 395 | % ... 396 | % \end{tikzpicture} 397 | % \end{sourceverb} 398 | % 399 | % 绘制结果如\autoref{fig:forloopcolork}所示。 400 | % 401 | % \flowchartset{ 402 | % proc fill color = orange!10, 403 | % test fill color = green!30, 404 | % io fill color = blue!30, 405 | % term fill color = red!30, 406 | % proc text width = 6em, 407 | % test text width = 5em, 408 | % } 409 | % \begin{figure}[!htp] 410 | % \centering 411 | % \begin{tikzpicture} 412 | % \node [proc] (p1) {表达式1}; 413 | % \node [test, join] (t1) {表达式2?}; 414 | % \node [proc] (p2) {循环体}; 415 | % \node [proc, join] (p3) {表达式3}; 416 | % 417 | % \node [coord, above = 0.5 of p1] (c1) {}; 418 | % \node [coord] (c2) at ($(p1)!0.35!(t1)$) {}; 419 | % \node [coord, below = 0.25 of p3] (c3) {}; 420 | % \node [coord, below = 0.2 of c3] (c4) {}; 421 | % \node [coord, below = 0.5 of c4] (c5) {}; 422 | % \node [coord, right = 0.5 of t1] (c6) {}; 423 | % \node [coord, left = 0.5 of t1] (ct) {}; 424 | % \node [coord] (c7) at (c3 -| ct) {}; 425 | % 426 | % \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 427 | % \draw [norm] (t1.south) -- (p2.north); 428 | % \path (t1.east) -- node [near start, above] {$N$} (c6); 429 | % \draw [norm] (t1.east) -- (c6) |- (c4) -- (c5); 430 | % 431 | % \draw [norm] (c1) -- (p1); 432 | % \draw [norm] (p3.south) |- (c7) |- (c2); 433 | % \end{tikzpicture} 434 | % \caption{彩色流程图} 435 | % \label{fig:forloopcolork} 436 | % \end{figure} 437 | % 438 | % \subsection{使用\env{tikzpicture}环境的绘图参数} 439 | % 可以使用任意合法的\env{tikzpicture}环境参数,如,可使用 440 | % \env{tikzpicture}环境的参数进行流程图缩放及字号设置: 441 | % 442 | % \begin{sourceverb} 443 | % \begin{tikzpicture}[font=\scriptsize, scale=0.5, 444 | % every node/.append style = {transform shape}] 445 | % ... 446 | % \end{tikzpicture} 447 | % \end{sourceverb} 448 | % 449 | % 绘制结果如\autoref{fig:forloopscaled}所示。 450 | % 451 | % \begin{figure}[!htp] 452 | % \centering 453 | % \begin{tikzpicture}[font=\scriptsize, scale=0.5, 454 | % every node/.append style = {transform shape}] 455 | % \node [proc] (p1) {表达式1}; 456 | % \node [test, join] (t1) {表达式2?}; 457 | % \node [proc] (p2) {循环体}; 458 | % \node [proc, join] (p3) {表达式3}; 459 | % 460 | % \node [coord, above = 0.5 of p1] (c1) {}; 461 | % \node [coord] (c2) at ($(p1)!0.35!(t1)$) {}; 462 | % \node [coord, below = 0.25 of p3] (c3) {}; 463 | % \node [coord, below = 0.2 of c3] (c4) {}; 464 | % \node [coord, below = 0.5 of c4] (c5) {}; 465 | % \node [coord, right = 0.5 of t1] (c6) {}; 466 | % \node [coord, left = 0.5 of t1] (ct) {}; 467 | % \node [coord] (c7) at (c3 -| ct) {}; 468 | % 469 | % \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 470 | % \draw [norm] (t1.south) -- (p2.north); 471 | % \path (t1.east) -- node [near start, above] {$N$} (c6); 472 | % \draw [norm] (t1.east) -- (c6) |- (c4) -- (c5); 473 | % 474 | % \draw [norm] (c1) -- (p1); 475 | % \draw [norm] (p3.south) |- (c7) |- (c2); 476 | % \end{tikzpicture} 477 | % \caption{流程图缩放} 478 | % \label{fig:forloopscaled} 479 | % \end{figure} 480 | % 481 | % \subsection{使用绘图命令参数} 482 | % 可以使用任意\cs{node}、\cs{draw}等绘图命令的合法参数调整当前绘图属性,如: 483 | % 484 | % \begin{sourcedisplay} 485 | % ...\\ 486 | % \cs{node}[test, join, \textcolor{red}{text width= 5em}](t1) \{表达式2?\};\\ 487 | % ...\\ 488 | % \cs{draw}[norm, \textcolor{red}{dash dot}](t1.east) -- (c6) \verb!|!- (c4) -- (c5);\\ 489 | % ...\\ 490 | % \cs{draw}[norm, \textcolor{red}{dashed}](p3.south) \verb!|!- (c7) \verb!|!- (c2);\\ 491 | % ...\\ 492 | % \end{sourcedisplay} 493 | % 494 | % 绘制结果如\autoref{fig:forloopdasheline}所示。 495 | % 496 | % \begin{figure}[!htp] 497 | % \centering 498 | % \begin{tikzpicture} 499 | % \node [proc] (p1) {表达式1}; 500 | % \node [test, join, text width= 5em] (t1) {表达式2?}; 501 | % \node [proc] (p2) {循环体}; 502 | % \node [proc, join] (p3) {表达式3}; 503 | % 504 | % \node [coord, above = 0.5 of p1] (c1) {}; 505 | % \node [coord] (c2) at ($(p1)!0.35!(t1)$) {}; 506 | % \node [coord, below = 0.25 of p3] (c3) {}; 507 | % \node [coord, below = 0.2 of c3] (c4) {}; 508 | % \node [coord, below = 0.5 of c4] (c5) {}; 509 | % \node [coord, right = 0.5 of t1] (c6) {}; 510 | % \node [coord, left = 0.5 of t1] (ct) {}; 511 | % \node [coord] (c7) at (c3 -| ct) {}; 512 | % 513 | % \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 514 | % \draw [norm] (t1.south) -- (p2.north); 515 | % \path (t1.east) -- node [near start, above] {$N$} (c6); 516 | % \draw [norm, dash dot] (t1.east) -- (c6) |- (c4) -- (c5); 517 | % 518 | % \draw [norm] (c1) -- (p1); 519 | % \draw [norm, dashed] (p3.south) |- (c7) |- (c2); 520 | % \end{tikzpicture} 521 | % \caption{使用绘图命令参数} 522 | % \label{fig:forloopdasheline} 523 | % \end{figure} 524 | % 525 | % \subsection{流程图示例} 526 | % \subsubsection{冒泡排序流程图} 527 | % 如下代码绘制如\autoref{fig:bubllesort}所示的冒泡排序流程图。 528 | % 529 | % \begin{sourceverb}[xleftmargin=0em] 530 | % \begin{figure}[!htp] 531 | % \centering 532 | % \begin{tikzpicture} 533 | % % 布置结点单元 534 | % \node [term] (st) {Begin}; 535 | % \node [proc, text width = 6em, join] (p1) {\verb|int i, j|\\ 536 | % \verb|int counter|}; 537 | % \node [proc, join] (p2) {\verb|i = 0|\\\verb|counter = 0|}; 538 | % \node [test, join] (t1) {\verb|i < n - 1|}; 539 | % \node [proc] (p3) {\verb|j = 0|}; 540 | % \node [test, join] (t2) {\verb|j < n - 1|}; 541 | % \node [test, text width = 6em] (t3) {\verb|a[j] > a[j + 1]|}; 542 | % \node [proc, text width = 8em] (p4) {\verb|Swap(a[j], a[j + 1])|}; 543 | % \node [proc, join] (p5) {\verb|counter++|\\\verb|j++|}; 544 | % \node [proc] (p6) {\verb|i++|}; 545 | % \node [proc, text width = 6em] (p7) {\verb|return counter|}; 546 | % \node [term, join] (end) {End}; 547 | % 548 | % % 布置用于连接的坐标结点,同时为其布置调试标记点。 549 | % \node [coord] (c1) at ($(p2.south)!0.5!(t1.north)$) {}; 550 | % \node [coord] (c2) at ($(p3.south)!0.5!(t2.north)$) {}; 551 | % \node [coord] (c3) at ($(p4.south)!0.5!(p5.north)$) {}; 552 | % \node [coord, below = 0.2 of p5] (c4) {}; 553 | % \node [coord, above = 0.25 of p6] (c5) {}; 554 | % \node [coord, below = 0.2 of p6] (c6) {}; 555 | % \node [coord, above = 0.25 of p7] (c7) {}; 556 | % \node [coord, right = 2.0 of t1] (c8) {}; 557 | % \node [coord, right = 1.5 of t2] (c9) {}; 558 | % \node [coord, right = 0.4 of t3] (c10) {}; 559 | % \node [coord, left = 1.5 of t2] (ct1) {}; 560 | % \node [coord, left = 2.0 of t2] (ct2) {}; 561 | % \node [coord] (c11) at (c6 -| ct2) {}; 562 | % \node [coord] (c12) at (c4 -| ct1) {}; 563 | % 564 | % % 判断框连线,每次绘制时,先绘制一个带有一个固定 565 | % % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 566 | % \path (t1.south) -- node [near start, right] {$Y$} (p3.north); 567 | % \draw [norm] (t1.south) -- (p3.north); 568 | % \path (t1.east) -- node [near start, above] {$N$} (c8); 569 | % \draw [norm] (t1.east) -- (c8) |- (c7) -- (p7.north); 570 | % 571 | % \path (t2.south) -- node [near start, right] {$Y$} (t3.north); 572 | % \draw [norm] (t2.south) -- (t3.north); 573 | % \path (t2.east) -- node [near start, above] {$N$} (c9); 574 | % \draw [norm] (t2.east) -- (c9) |- (c5) -- (p6.north); 575 | % 576 | % \path (t3.south) -- node [near start, right] {$Y$} (p4.north); 577 | % \draw [norm] (t3.south) -- (p4.north); 578 | % \path (t3.east) -- node [near start, above] {$N$} (c10); 579 | % \draw [norm] (t3.east) -- (c10) |- (c3); 580 | % 581 | % % 其它连线 582 | % \draw [norm](p5.south) |- (c12) |- (c2); 583 | % \draw [norm](p6.south) |- (c11) |- (c1); 584 | % \end{tikzpicture} 585 | % \caption{冒泡排序流程图} 586 | % \label{fig:bubllesort} 587 | % \end{figure} 588 | % \end{sourceverb} 589 | % 590 | % \flowchartset{ 591 | % free color = green, 592 | % norm color = blue, 593 | % cong color = red, 594 | % proc fill color = orange!10, 595 | % test fill color = green!30, 596 | % io fill color = blue!30, 597 | % term fill color = red!30, 598 | % proc text width = 10em, 599 | % test text width = 8em, 600 | % } 601 | % 602 | % \begin{figure}[!htp] 603 | % \centering 604 | % \begin{tikzpicture} 605 | % % 布置结点单元 606 | % \node [term] (st) {Begin}; 607 | % \node [proc, join] (p1) {|int i, j|\\|int counter|}; 608 | % \node [proc, join] (p2) {|i = 0|\\|counter = 0|}; 609 | % \node [test, join] (t1) {|i < n - 1|}; 610 | % \node [proc] (p3) {|j = 0|}; 611 | % \node [test, join] (t2) {|j < n - 1|}; 612 | % \node [test] (t3) {|a[j] > a[j + 1]|}; 613 | % \node [proc] (p4) {|Swap(a[j], a[j + 1])|}; 614 | % \node [proc, join] (p5) {|counter++|\\|j++|}; 615 | % \node [proc] (p6) {|i++|}; 616 | % \node [proc] (p7) {|return counter|}; 617 | % \node [term, join] (end) {End}; 618 | % 619 | % % 布置用于连接的坐标结点,同时为其布置调试标记点。 620 | % \node [coord] (c1) at ($(p2.south)!0.5!(t1.north)$) {}; 621 | % \node [coord] (c2) at ($(p3.south)!0.5!(t2.north)$) {}; 622 | % \node [coord] (c3) at ($(p4.south)!0.5!(p5.north)$) {}; 623 | % \node [coord, below = 0.2 of p5] (c4) {}; 624 | % \node [coord, above = 0.25 of p6] (c5) {}; 625 | % \node [coord, below = 0.2 of p6] (c6) {}; 626 | % \node [coord, above = 0.25 of p7] (c7) {}; 627 | % \node [coord, right = 2.0 of t1] (c8) {}; 628 | % \node [coord, right = 1.5 of t2] (c9) {}; 629 | % \node [coord, right = 0.4 of t3] (c10) {}; 630 | % \node [coord, left = 1.5 of t2] (ct1) {}; 631 | % \node [coord, left = 2.0 of t2] (ct2) {}; 632 | % \node [coord] (c11) at (c6 -| ct2) {}; 633 | % \node [coord] (c12) at (c4 -| ct1) {}; 634 | % 635 | % % 判断框连线,每次绘制时,先绘制一个带有一个固定 636 | % % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 637 | % \path (t1.south) -- node [near start, right] {$Y$} (p3.north); 638 | % \draw [norm] (t1.south) -- (p3.north); 639 | % \path (t1.east) -- node [near start, above] {$N$} (c8); 640 | % \draw [norm] (t1.east) -- (c8) |- (c7) -- (p7.north); 641 | % 642 | % \path (t2.south) -- node [near start, right] {$Y$} (t3.north); 643 | % \draw [norm] (t2.south) -- (t3.north); 644 | % \path (t2.east) -- node [near start, above] {$N$} (c9); 645 | % \draw [norm] (t2.east) -- (c9) |- (c5) -- (p6.north); 646 | % 647 | % \path (t3.south) -- node [near start, right] {$Y$} (p4.north); 648 | % \draw [norm] (t3.south) -- (p4.north); 649 | % \path (t3.east) -- node [near start, above] {$N$} (c10); 650 | % \draw [norm] (t3.east) -- (c10) |- (c3); 651 | % 652 | % % 其它连线 653 | % \draw [norm](p5.south) |- (c12) |- (c2); 654 | % \draw [norm](p6.south) |- (c11) |- (c1); 655 | % \end{tikzpicture} 656 | % \caption{冒泡排序流程图} 657 | % \label{fig:bubllesort} 658 | % \end{figure} 659 | % 660 | % \newpage 661 | % \subsubsection{素数判定流程图} 662 | % 如下代码绘制如\autoref{fig:primejudge}所示的素数判定流程图。 663 | % 664 | % \begin{sourceverb}[xleftmargin=0em] 665 | % \begin{figure}[!htp] 666 | % \centering 667 | % \begin{tikzpicture} 668 | % % 布置结点单元 669 | % \node [term] (st) {开始}; 670 | % \node [proc, join] (p1) {\verb|int divisor|}; 671 | % \node [test, join] (t1) {\verb|n <= 1|}; 672 | % \node [proc] (p2) {\verb|divisor = 2|}; 673 | % \node [test, join] (t2) {\verb|divisor * divisor <= n|}; 674 | % \node [test] (t3) {\verb|n % divisor == 0|}; 675 | % \node [proc] (p3) {\verb|divisor++|}; 676 | % \node [term, below = 1.6 of p3] (end) {结束}; 677 | % \node [proc, left = 4.8 of t2] (p4) {\verb|return 0|}; 678 | % \node [proc, right = 3.5 of p3] (p5) {\verb|return 0|}; 679 | % \node [proc, right = 5.8 of t3] (p6) {\verb|return 1|}; 680 | % 681 | % % 布置用于连接的坐标结点,同时为其布置调试标记点。 682 | % \node [coord] (c1) at ($(p2.south)!0.5!(t2.north)$) {}; 683 | % \node [coord, below = 0.25 of p3] (c2) {}; 684 | % \node [coord, above = 0.5 of end] (c3) {}; 685 | % \node [coord, left = 0.5 of t2] (ct) {}; 686 | % \node [coord] (c4) at (c3 -| p5) {}; 687 | % \node [coord] (c5) at (c2 -| ct) {}; 688 | % 689 | % % 判断框连线,每次绘制时,先绘制一个带有一个固定 690 | % % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 691 | % \path (t1.south) -- node [near start, right] {$N$} (p2.north); 692 | % \draw [norm] (t1.south) -- (p2.north); 693 | % \path (t1.west) -| node [near start, above] {$Y$} (p4.north); 694 | % \draw [norm] (t1.west) -| (p4.north); 695 | % 696 | % \path (t2.south) -- node [near start, right] {$Y$} (t3.north); 697 | % \draw [norm] (t2.south) -- (t3.north); 698 | % \path (t2.east) -| node [near start, above] {$N$} (p6.north); 699 | % \draw [norm] (t2.east) -| (p6.north); 700 | % 701 | % \path (t3.south) -- node [near start, right] {$N$} (p3.north); 702 | % \draw [norm] (t3.south) -- (p3.north); 703 | % \path (t3.east) -| node [near start, above] {$Y$} (p5.north); 704 | % \draw [norm] (t3.east) -| (p5.north); 705 | % 706 | % % 其它连线 707 | % \draw [norm](p3.south) |- (c5) |- (c1); 708 | % \draw [norm](p4.south) |- (c3); 709 | % \draw [norm](p4.south) |- (c3) -- (end); 710 | % \draw [norm](p5.south) -- (c4); 711 | % \draw [norm](p6.south) |- (c3); 712 | % \draw [norm](p6.south) |- (c3) -- (end); 713 | % \end{tikzpicture} 714 | % \caption{素数判定流程图} 715 | % \label{fig:primejudge} 716 | % \end{figure} 717 | % \end{sourceverb} 718 | % 719 | % \flowchartset{ 720 | % proc fill color = orange!10, 721 | % test fill color = green!30, 722 | % io fill color = blue!30, 723 | % term fill color = red!30, 724 | % proc text width = 6em, 725 | % test text width = 10em, 726 | % } 727 | % 728 | % \begin{figure}[!htp] 729 | % \centering 730 | % \begin{tikzpicture}[scale=0.5] 731 | % % 布置结点单元 732 | % \node [term] (st) {开始}; 733 | % \node [proc, join] (p1) {|int divisor|}; 734 | % \node [test, join] (t1) {b|n <= 1|}; 735 | % \node [proc] (p2) {|divisor = 2|}; 736 | % \node [test, join] (t2) {|divisor * divisor <= n|}; 737 | % \node [test] (t3) {|n % divisor == 0|}; 738 | % \node [proc] (p3) {|divisor++|}; 739 | % \node [term, below = 1.6 of p3] (end) {结束}; 740 | % \node [proc, left = 4.8 of t2] (p4) {|return 0|}; 741 | % \node [proc, right = 3.5 of p3] (p5) {|return 0|}; 742 | % \node [proc, right = 5.8 of t3] (p6) {|return 1|}; 743 | % 744 | % % 布置用于连接的坐标结点,同时为其布置调试标记点。 745 | % \node [coord] (c1) at ($(p2.south)!0.5!(t2.north)$) {}; 746 | % \node [coord, below = 0.25 of p3] (c2) {}; 747 | % \node [coord, above = 0.5 of end] (c3) {}; 748 | % \node [coord, left = 0.5 of t2] (ct) {}; 749 | % \node [coord] (c4) at (c3 -| p5) {}; 750 | % \node [coord] (c5) at (c2 -| ct) {}; 751 | % 752 | % % 判断框连线,每次绘制时,先绘制一个带有一个固定 753 | % % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 754 | % \path (t1.south) -- node [near start, right] {$N$} (p2.north); 755 | % \draw [norm] (t1.south) -- (p2.north); 756 | % \path (t1.west) -| node [near start, above] {$Y$} (p4.north); 757 | % \draw [norm] (t1.west) -| (p4.north); 758 | % 759 | % \path (t2.south) -- node [near start, right] {$Y$} (t3.north); 760 | % \draw [norm] (t2.south) -- (t3.north); 761 | % \path (t2.east) -| node [near start, above] {$N$} (p6.north); 762 | % \draw [norm] (t2.east) -| (p6.north); 763 | % 764 | % \path (t3.south) -- node [near start, right] {$N$} (p3.north); 765 | % \draw [norm] (t3.south) -- (p3.north); 766 | % \path (t3.east) -| node [near start, above] {$Y$} (p5.north); 767 | % \draw [norm] (t3.east) -| (p5.north); 768 | % 769 | % % 其它连线 770 | % \draw [norm](p3.south) |- (c5) |- (c1); 771 | % \draw [norm](p4.south) |- (c3); 772 | % \draw [norm](p4.south) |- (c3) -- (end); 773 | % \draw [norm](p5.south) -- (c4); 774 | % \draw [norm](p6.south) |- (c3); 775 | % \draw [norm](p6.south) |- (c3) -- (end); 776 | % \end{tikzpicture} 777 | % \caption{素数判定流程图} 778 | % \label{fig:primejudge} 779 | % \end{figure} 780 | % 781 | % \newpage 782 | % \subsubsection{求最大公约数流程图} 783 | % 如下代码绘制如\autoref{fig:getgcd}所示的求最大公约数流程图。 784 | % 785 | % \begin{sourceverb}[xleftmargin=0em] 786 | % \begin{figure}[!htp] 787 | % \centering 788 | % \begin{tikzpicture} 789 | % % 布置结点单元 790 | % % 用异或交换两个整数 791 | % \node [term] (st) {Begin}; 792 | % \node [proc, join] (p1) {\verb|int r = 0|}; 793 | % \node [test, join] (t1) {\verb|m < n|}; 794 | % \node [proc] (p2) {\verb|m ^= n|\\\verb|n ^= m|\\\verb|m ^= n|}; 795 | % \node [test, join] (t2) {\verb|n != 0|}; 796 | % \node [proc] (p3) {\verb|r = m % n|\\\verb|m = n|\\\verb|n = r|}; 797 | % \node [proc] (p4) {\verb|return m|}; 798 | % \node [term, join] (end) {End}; 799 | % 800 | % % 布置用于连接的坐标结点,同时为其布置调试标记点。 801 | % \node [coord] (c1) at ($(p2.south)!0.5!(t2.north)$) {}; 802 | % \node [coord, below = 0.25 of p3] (c2) {}; 803 | % \node [coord, above = 0.25 of p4] (c3) {}; 804 | % \node [coord, right = 1.0 of t1] (c4) {}; 805 | % \node [coord, right = 1.0 of t2] (c5) {}; 806 | % \node [coord, left = 1.0 of t2] (ct) {}; 807 | % \node [coord] (c6) at (ct |- c2) {}; 808 | % 809 | % % 判断框连线,每次绘制时,先绘制一个带有一个固定 810 | % % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 811 | % \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 812 | % \draw [norm] (t1.south) -- (p2.north); 813 | % \path (t1.east) -- node [near start, above] {$N$} (c4); 814 | % \draw [norm] (t1.east) -- (c4) |- (c1); 815 | % \path (t2.south) -- node [near start, right] {$Y$} (p3.north); 816 | % \draw [norm] (t2.south) -- (p3.north); 817 | % \path (t2.east) -- node [near start, above] {$N$} (c5); 818 | % \draw [norm] (t2.east) -- (c5) |- (c3) -- (p4.north); 819 | % 820 | % % 其它连线 821 | % \draw [norm](p3.south) |- (c6) |- (c1); 822 | % \end{tikzpicture} 823 | % \caption{求最大公约数} 824 | % \label{fig:getgcd} 825 | % \end{figure} 826 | % \end{sourceverb} 827 | % 828 | % \flowchartset{ 829 | % proc fill color = orange!10, 830 | % test fill color = green!30, 831 | % io fill color = blue!30, 832 | % term fill color = red!30, 833 | % proc text width = 5em, 834 | % test text width = 5em, 835 | % } 836 | % 837 | % \begin{figure}[!htp] 838 | % \centering 839 | % \begin{tikzpicture} 840 | % % 布置结点单元 841 | % % 用异或交换两个整数 842 | % \node [term] (st) {Begin}; 843 | % \node [proc, join] (p1) {|int r = 0|}; 844 | % \node [test, join] (t1) {|m < n|}; 845 | % \node [proc] (p2) {|m ^= n|\\|n ^= m|\\|m ^= n|}; 846 | % \node [test, join] (t2) {|n != 0|}; 847 | % \node [proc] (p3) {|r = m % n|\\|m = n|\\|n = r|}; 848 | % \node [proc] (p4) {|return m|}; 849 | % \node [term, join] (end) {End}; 850 | % 851 | % % 布置用于连接的坐标结点,同时为其布置调试标记点。 852 | % \node [coord] (c1) at ($(p2.south)!0.5!(t2.north)$) {}; 853 | % \node [coord, below = 0.25 of p3] (c2) {}; 854 | % \node [coord, above = 0.25 of p4] (c3) {}; 855 | % \node [coord, right = 1.0 of t1] (c4) {}; 856 | % \node [coord, right = 1.0 of t2] (c5) {}; 857 | % \node [coord, left = 1.0 of t2] (ct) {}; 858 | % \node [coord] (c6) at (ct |- c2) {}; 859 | % 860 | % % 判断框连线,每次绘制时,先绘制一个带有一个固定 861 | % % 位置标注的路径(path),然后再绘制箭头本身(arrow)。 862 | % \path (t1.south) -- node [near start, right] {$Y$} (p2.north); 863 | % \draw [norm] (t1.south) -- (p2.north); 864 | % \path (t1.east) -- node [near start, above] {$N$} (c4); 865 | % \draw [norm] (t1.east) -- (c4) |- (c1); 866 | % \path (t2.south) -- node [near start, right] {$Y$} (p3.north); 867 | % \draw [norm] (t2.south) -- (p3.north); 868 | % \path (t2.east) -- node [near start, above] {$N$} (c5); 869 | % \draw [norm] (t2.east) -- (c5) |- (c3) -- (p4.north); 870 | % 871 | % % 其它连线 872 | % \draw [norm](p3.south) |- (c6) |- (c1); 873 | % \end{tikzpicture} 874 | % \caption{求最大公约数} 875 | % \label{fig:getgcd} 876 | % \end{figure} 877 | % 878 | % \newpage 879 | % \section{代码实现} 880 | % 该宏包仅需要载入|tikz|和|xifthen|宏包,如果这些宏包没有载入,则自 881 | % 动载入这些宏包。 882 | % \begin{macrocode} 883 | \RequirePackage{tikz} 884 | \RequirePackage{xifthen} 885 | % 886 | % \end{macrocode} 887 | % \subsection{宏包选项} 888 | % 使用 \pkg{kvoptions} 来处理传给该宏包的参数。 889 | % \begin{macrocode} 890 | \RequirePackage{kvoptions} 891 | \SetupKeyvalOptions{ 892 | family=flowchart, 893 | prefix=flowchart@, 894 | setkeys=\kvsetkeys 895 | } 896 | % \end{macrocode} 897 | % 898 | % 定义调试状态参数(布尔类型)。 899 | % \begin{macrocode} 900 | \DeclareBoolOption[false]{debug} 901 | % \end{macrocode} 902 | % 903 | % 参数解析,获取定义的宏包参数。 904 | % \begin{macrocode} 905 | \DeclareDefaultOption{} 906 | \kvsetkeys{flowchart}{} 907 | \ProcessKeyvalOptions* 908 | % \end{macrocode} 909 | 910 | % 载入需要的\tkz{}宏包运行库。 911 | % \begin{macrocode} 912 | \usetikzlibrary{ 913 | arrows.meta, % 箭头形状 914 | shapes.geometric, % 几何形状 915 | chains, % 链式布局 916 | calc, % 坐标计算 917 | } 918 | % \end{macrocode} 919 | % 920 | % \subsection{配置命令} 921 | % 为|\flowchartset|命令定义一个|pgfkeys|族,所有配置参数(例如: 922 | % \meta{norm color}等)都会存储在|/flowchart|PGF键中。这能够确保这些配 923 | % 置参数不会覆盖别的同类参数。 924 | % \begin{macrocode} 925 | \pgfkeys{ 926 | /flowchart/.is family, 927 | /flowchart/.search also={/tikz}, 928 | } 929 | 930 | \def\flowchartset{\pgfqkeys{/flowchart}} 931 | % \end{macrocode} 932 | % 然后,定义存储这些参数值的宏命令。 933 | % \begin{macrocode} 934 | \flowchartset{ 935 | free color/.store in = \freecolor, % 自由连线颜色 936 | norm color/.store in = \normcolor, % 常规连线颜色 937 | cong color/.store in = \congcolor, % 关联连线颜色 938 | proc fill color/.store in = \procfillcolor, % 顺序处理框填充颜色 939 | test fill color/.store in = \testfillcolor, % 判断框填充颜色 940 | io fill color/.store in = \iofillcolor, % 输入/输出框填充颜色 941 | term fill color/.store in = \termfillcolor, % 开始/结束框填充颜色 942 | proc text width/.store in = \proctxtwd, % 顺序处理框宽度 943 | test text width/.store in = \testtxtwd, % 判断框宽度 944 | io text width/.store in = \iotxtwd, % 输入/输出框宽度 945 | term text width/.store in = \termtxtwd, % 开始/结束宽度 946 | chain direction/.store in = \chaindir, % 结点自动布置方向 947 | minimum node distance/.store in = \minnodedis, % 最小结点间距 948 | maximum node distance/.store in = \maxnodedis, % 最大结点间距 949 | border line width/.store in = \bdlinewd, % 各类流程框边框宽度 950 | flow line width/.store in = \flowlinewd, % 各类流程线线条宽度 951 | stealth length/.store in = \stealthlen, % 箭头长度 952 | stealth width/.store in = \stealthwd, % 箭头宽度 953 | } 954 | % \end{macrocode} 955 | % 956 | % \subsection{默认参数值} 957 | % 为各个参数设置默认值以确保预设的各个宏的值有效,这些值可以由用户单独 958 | % 进行修改,修改后的值会覆盖参数默认值。 959 | % \begin{macrocode} 960 | \flowchartset{ 961 | free color = green, % 自由连线颜色(默认取green) 962 | norm color = blue, % 常规连线颜色(默认取blue) 963 | cong color = red, % 关联连线颜色(默认取red) 964 | proc fill color = white, % 顺序处理框填充颜色(默认取白色) 965 | test fill color = white, % 判断框填充颜色(默认取白色) 966 | io fill color = white, % 输入/输出框填充颜色(默认取白色) 967 | term fill color = white, % 开始/结束框填充颜色(默认取白色) 968 | proc text width = 8em, % 顺序处理框宽度(默认取8em) 969 | test text width = 5em, % 判断框宽度(默认取5em) 970 | io text width = 6em, % 输入/输出框宽度(默认取6em) 971 | term text width = 3em, % 开始/结束宽度(默认取3em) 972 | chain direction = below, % 结点自动布置方向(默认取below) 973 | minimum node distance = 6mm, % 最小结点间距(默认取6mm) 974 | maximum node distance = 60mm, % 最大结点间距(默认取60mm) 975 | border line width = \pgflinewidth, % 各类流程框边框宽度(默认取当前线条宽度) 976 | flow line width = \pgflinewidth, % 各类流程线线条宽度(默认取当前线条宽度) 977 | stealth length = 1.5mm, % 箭头长度(默认取1.5mm) 978 | stealth width = 1.0mm, % 箭头宽度(默认取1.0mm) 979 | } 980 | % \end{macrocode} 981 | % 982 | % \subsection{样式定义} 983 | % 以下是所有绘制流程图中需要的样式定义。 984 | % \begin{macrocode} 985 | \tikzset{ 986 | % \end{macrocode} 987 | % 首先,定义结点布局方式: 988 | % \begin{macrocode} 989 | start chain = going \chaindir, % 结点自动布置方向(默认取below) 990 | node distance = \minnodedis and \maxnodedis, % 结点间距 991 | every join/.style = {norm}, % 默认自动连接线的连线样式 992 | % \end{macrocode} 993 | % 其次,定义基础绘图样式: 994 | % \begin{macrocode} 995 | % 流程框样式的基础样式 996 | base/.style = {line width = \bdlinewd, % 边框线宽 997 | draw, % 绘制边框 998 | on chain, % 沿布局方向绘制 999 | on grid, % 沿网格布局 1000 | align=center, % 内容居中对齐 1001 | minimum height=2ex, % 流程框最小高度 1002 | }, 1003 | % \end{macrocode} 1004 | % 接下来,定义|proc|、|test|、|io|、|term|四个|\textbackslash node|命令 1005 | % 的绘图样式: 1006 | % \begin{macrocode} 1007 | % 顺序处理框样式 1008 | proc/.style={base, % 基础样式 1009 | rectangle, % 矩形边框 1010 | text width=\proctxtwd, % 最大文本宽度(超过会自动换行) 1011 | fill=\procfillcolor, % 填充色 1012 | }, 1013 | % 判断框样式 1014 | test/.style={base, % 基础样式 1015 | diamond, % 菱形边框 1016 | aspect=2.5, % 长高比例 1017 | text width=\testtxtwd, % 最大文本宽度(超过会自动换行) 1018 | fill=\testfillcolor, % 填充色 1019 | }, 1020 | % 输入/输出框样式 1021 | io/.style={base, % 基础样式 1022 | trapezium, % 平行四边形 1023 | trapezium left angle=70, % 平行四边形左倾角 1024 | trapezium right angle=110, % 平行四边形右倾角 1025 | text width=\iotxtwd, % 最大文本宽度(超过会自动换行) 1026 | fill=\iofillcolor, % 填充色 1027 | }, 1028 | % 开始/结束框样式 1029 | term/.style={proc, % 基于proc样式 1030 | rounded corners=2.0mm, % 为矩形添加圆角属性 1031 | text width=\termtxtwd, % 最大文本宽度(超过会自动换行) 1032 | fill=\termfillcolor, % 填充色 1033 | }, 1034 | % \end{macrocode} 1035 | % 再下来,定义流程线交点绘制样式: 1036 | % \begin{macrocode} 1037 | % 流程连接点样式 1038 | connector/.style = {draw, % 绘制边框 1039 | circle, % 圆形 1040 | node distance=3cm, % 节点间距 1041 | }, 1042 | % 绕接连线点样式(不相交的两个交汇路径) 1043 | connect/.style args={(#1) to (#2) over (#3) by #4}{ 1044 | insert path={ 1045 | let \p1=($(#1)-(#3)$), \n1={veclen(\x1,\y1)}, 1046 | \n2={atan2(\y1,\x1)}, \n3={abs(#4)}, \n4={#4>0 ?-180:180} in 1047 | (#1) -- ($(#1)!\n1-\n3!(#3)$) arc (\n2:\n2+\n4:\n3) -- (#2) 1048 | } 1049 | }, 1050 | % \end{macrocode} 1051 | % 还需要定义流程线转角点|node|命令样式: 1052 | % \begin{macrocode} 1053 | % coord结点样式(用于布置流程线连接点) 1054 | coord/.style={coordinate, % 笛卡尔坐标系 1055 | %on chain, % 沿布局方向绘制 1056 | %on grid, % 沿网格布局 1057 | node distance=6mm and 25mm, % 节点间距 1058 | }, 1059 | % \end{macrocode} 1060 | % 为|cmark|调试标记命令绘制样式: 1061 | % \begin{macrocode} 1062 | % nmark结点样式(用于布置调试坐标标记点) 1063 | nmark/.style={draw, % 绘制边框 1064 | cyan, % 青色 1065 | circle, % 圆形 1066 | font={\sffamily\bfseries}, % 字体 1067 | }, 1068 | % \end{macrocode} 1069 | % 另外,需要定义各类流程线绘制样式: 1070 | % \begin{macrocode} 1071 | % ------------------------------------------------- 1072 | % 无箭头连线样式 1073 | lnorm/.style={line width = \flowlinewd, % 线宽 1074 | draw, % 绘制 1075 | \normcolor, % 颜色 1076 | }, 1077 | lfree/.style={line width = \flowlinewd, 1078 | draw, 1079 | \freecolor, 1080 | }, 1081 | lcong/.style={line width = \flowlinewd, 1082 | draw, 1083 | \congcolor, 1084 | }, 1085 | % 流程线实心交点样式 1086 | dotnorm/.style={draw, % 绘制 1087 | fill = \normcolor, % 填充颜色 1088 | \normcolor, % 颜色 1089 | }, 1090 | dotfree/.style={draw, 1091 | fill = \freecolor, 1092 | \freecolor, 1093 | }, 1094 | dotcong/.style={draw, 1095 | fill = \congcolor, 1096 | \congcolor, 1097 | }, 1098 | % 流程线空心交点样式 1099 | cdotnorm/.style={draw, % 绘制 1100 | \normcolor, % 颜色 1101 | }, 1102 | cdotfree/.style={draw, 1103 | \freecolor, 1104 | }, 1105 | cdotcong/.style={draw, 1106 | \congcolor, 1107 | }, 1108 | % 带箭头连线样式 1109 | norm/.style={line width = \flowlinewd, % 线宽 1110 | -{Stealth[length=\stealthlen, % 箭头长度 1111 | width=\stealthwd, % 箭头宽度 1112 | ] 1113 | }, 1114 | draw, % 绘制 1115 | \normcolor, % 颜色 1116 | }, 1117 | free/.style={line width = \flowlinewd, 1118 | -{Stealth[length=\stealthlen, 1119 | width=\stealthwd, 1120 | ] 1121 | }, 1122 | draw, 1123 | \freecolor, 1124 | }, 1125 | cong/.style={line width = \flowlinewd, 1126 | -{Stealth[length=\stealthlen, 1127 | width=\stealthwd, 1128 | ] 1129 | }, 1130 | draw, 1131 | \congcolor, 1132 | }, 1133 | % \end{macrocode} 1134 | % 最后,再定义一个流程线标注文本样式: 1135 | % \begin{macrocode} 1136 | % 斜体字样式 1137 | it/.style={font={\small\itshape}}, 1138 | } 1139 | % \end{macrocode} 1140 | % 1141 | % \subsection{调试命令定义} 1142 | % 为便于绘制过程中,能够直观连接各个流程线转角点,定义|cmark|命令,以绘制转角点标记。 1143 | % \begin{macrocode} 1144 | %% 判断是否为宏包传入了debug参数以打开调试功能,若没有传入debug参数,则关闭调试功能。 1145 | \ifflowchart@debug 1146 | % \end{macrocode} 1147 | % 传入了debug参数,创建用于调试的图层。 1148 | % \begin{macrocode} 1149 | % 设置一个用于调试的标记符号图层,注意确保这一图层位于顶层 1150 | \pgfdeclarelayer{marx} 1151 | \pgfsetlayers{main,marx} 1152 | % \end{macrocode} 1153 | % 定义|\textbackslash cmark|命令。 1154 | % \begin{macrocode} 1155 | \newcommand{\cmark}[2][]{% 1156 | \begin{pgfonlayer}{marx} 1157 | \node [nmark] at (c#2#1) {#2}; 1158 | \end{pgfonlayer}{marx} 1159 | } 1160 | % \end{macrocode} 1161 | % 未传入了debug参数,定义一个空的|cmark|命令。 1162 | % \begin{macrocode} 1163 | \else 1164 | \newcommand{\cmark}[2][]{\relax} 1165 | \fi 1166 | % \end{macrocode} 1167 | % \Finale 1168 | \endinput 1169 | 1170 | % \endinput 1171 | % Local Variables: 1172 | % mode: doctex 1173 | % TeX-master: t 1174 | % End: 1175 | -------------------------------------------------------------------------------- /tikz-flowchart.ins: -------------------------------------------------------------------------------- 1 | %% 2 | %% Copyright (C) 2019 by Geng Nan 3 | %% 4 | %% This work may be distributed and/or modified under the 5 | %% conditions of the LaTeX Project Public License, either version 1.3 6 | %% of this license or (at your option) any later version. 7 | %% The latest version of this license is in 8 | %% 9 | %% http://www.latex-project.org/lppl.txt 10 | %% 11 | %% and version 1.3 or later is part of all distributions of LaTeX 12 | %% version 2005/12/01 or later. 13 | %% 14 | 15 | \input docstrip 16 | \preamble 17 | 18 | This is a generated file. 19 | 20 | Copyright (C) 2019 by Geng Nan 21 | 22 | This work may be distributed and/or modified under the 23 | conditions of the LaTeX Project Public License, either version 1.3 24 | of this license or (at your option) any later version. 25 | The latest version of this license is in 26 | 27 | http://www.latex-project.org/lppl.txt 28 | 29 | and version 1.3 or later is part of all distributions of LaTeX 30 | version 2005/12/01 or later. 31 | 32 | \endpreamble 33 | 34 | 35 | \keepsilent 36 | \askforoverwritefalse 37 | 38 | \usedir{tex/latex/tikz-flowchart} 39 | 40 | % the package 41 | \generate{\file{tikz-flowchart.sty}{\from{tikz-flowchart.dtx}{package}}} 42 | 43 | % message 44 | \obeyspaces 45 | \Msg{****************************************************} 46 | \Msg{* *} 47 | \Msg{* To finish the installation you have to move the *} 48 | \Msg{* following file into a directory searched by TeX: *} 49 | \Msg{* *} 50 | \Msg{* tikz-flowchart.sty *} 51 | \Msg{* *} 52 | \Msg{* To produce the documentation run the file *} 53 | \Msg{* tikz-flowchart.dtx through LaTeX. *} 54 | \Msg{* *} 55 | \Msg{****************************************************} 56 | 57 | \endbatchfile 58 | -------------------------------------------------------------------------------- /tikz-flowchart.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/registor/tikz-flowchart/31152c9c7d957d84ebe7f440c27e65e47327e7b9/tikz-flowchart.pdf -------------------------------------------------------------------------------- /tikz-flowchart.sty: -------------------------------------------------------------------------------- 1 | %% 2 | %% This is file `tikz-flowchart.sty', 3 | %% generated with the docstrip utility. 4 | %% 5 | %% The original source files were: 6 | %% 7 | %% tikz-flowchart.dtx (with options: `package') 8 | %% 9 | %% This is a generated file. 10 | %% 11 | %% Copyright (C) 2019 by Geng Nan 12 | %% 13 | %% This work may be distributed and/or modified under the 14 | %% conditions of the LaTeX Project Public License, either version 1.3 15 | %% of this license or (at your option) any later version. 16 | %% The latest version of this license is in 17 | %% 18 | %% http://www.latex-project.org/lppl.txt 19 | %% 20 | %% and version 1.3 or later is part of all distributions of LaTeX 21 | %% version 2005/12/01 or later. 22 | %% 23 | \NeedsTeXFormat{LaTeX2e}[2011/06/27] 24 | \ProvidesPackage{tikz-flowchart} 25 | [2019/08/20 v1.0.01 draw flowchart using TikZ] 26 | \RequirePackage{tikz} 27 | \RequirePackage{xifthen} 28 | \RequirePackage{kvoptions} 29 | \SetupKeyvalOptions{ 30 | family=flowchart, 31 | prefix=flowchart@, 32 | setkeys=\kvsetkeys 33 | } 34 | \DeclareBoolOption[false]{debug} 35 | \DeclareDefaultOption{} 36 | \kvsetkeys{flowchart}{} 37 | \ProcessKeyvalOptions* 38 | 39 | \usetikzlibrary{ 40 | arrows.meta, % 箭头形状 41 | shapes.geometric, % 几何形状 42 | chains, % 链式布局 43 | calc, % 坐标计算 44 | } 45 | \pgfkeys{ 46 | /flowchart/.is family, 47 | /flowchart/.search also={/tikz}, 48 | } 49 | 50 | \def\flowchartset{\pgfqkeys{/flowchart}} 51 | \flowchartset{ 52 | free color/.store in = \freecolor, % 自由连线颜色 53 | norm color/.store in = \normcolor, % 常规连线颜色 54 | cong color/.store in = \congcolor, % 关联连线颜色 55 | proc fill color/.store in = \procfillcolor, % 顺序处理框填充颜色 56 | test fill color/.store in = \testfillcolor, % 判断框填充颜色 57 | io fill color/.store in = \iofillcolor, % 输入/输出框填充颜色 58 | term fill color/.store in = \termfillcolor, % 开始/结束框填充颜色 59 | proc text width/.store in = \proctxtwd, % 顺序处理框宽度 60 | test text width/.store in = \testtxtwd, % 判断框宽度 61 | io text width/.store in = \iotxtwd, % 输入/输出框宽度 62 | term text width/.store in = \termtxtwd, % 开始/结束宽度 63 | chain direction/.store in = \chaindir, % 结点自动布置方向 64 | minimum node distance/.store in = \minnodedis, % 最小结点间距 65 | maximum node distance/.store in = \maxnodedis, % 最大结点间距 66 | border line width/.store in = \bdlinewd, % 各类流程框边框宽度 67 | flow line width/.store in = \flowlinewd, % 各类流程线线条宽度 68 | stealth length/.store in = \stealthlen, % 箭头长度 69 | stealth width/.store in = \stealthwd, % 箭头宽度 70 | } 71 | \flowchartset{ 72 | free color = green, % 自由连线颜色(默认取green) 73 | norm color = blue, % 常规连线颜色(默认取blue) 74 | cong color = red, % 关联连线颜色(默认取red) 75 | proc fill color = white, % 顺序处理框填充颜色(默认取白色) 76 | test fill color = white, % 判断框填充颜色(默认取白色) 77 | io fill color = white, % 输入/输出框填充颜色(默认取白色) 78 | term fill color = white, % 开始/结束框填充颜色(默认取白色) 79 | proc text width = 8em, % 顺序处理框宽度(默认取8em) 80 | test text width = 5em, % 判断框宽度(默认取5em) 81 | io text width = 6em, % 输入/输出框宽度(默认取6em) 82 | term text width = 3em, % 开始/结束宽度(默认取3em) 83 | chain direction = below, % 结点自动布置方向(默认取below) 84 | minimum node distance = 6mm, % 最小结点间距(默认取6mm) 85 | maximum node distance = 60mm, % 最大结点间距(默认取60mm) 86 | border line width = \pgflinewidth, % 各类流程框边框宽度(默认取当前线条宽度) 87 | flow line width = \pgflinewidth, % 各类流程线线条宽度(默认取当前线条宽度) 88 | stealth length = 1.5mm, % 箭头长度(默认取1.5mm) 89 | stealth width = 1.0mm, % 箭头宽度(默认取1.0mm) 90 | } 91 | \tikzset{ 92 | start chain = going \chaindir, % 结点自动布置方向(默认取below) 93 | node distance = \minnodedis and \maxnodedis, % 结点间距 94 | every join/.style = {norm}, % 默认自动连接线的连线样式 95 | % 流程框样式的基础样式 96 | base/.style = {line width = \bdlinewd, % 边框线宽 97 | draw, % 绘制边框 98 | on chain, % 沿布局方向绘制 99 | on grid, % 沿网格布局 100 | align=center, % 内容居中对齐 101 | minimum height=2ex, % 流程框最小高度 102 | }, 103 | % 顺序处理框样式 104 | proc/.style={base, % 基础样式 105 | rectangle, % 矩形边框 106 | text width=\proctxtwd, % 最大文本宽度(超过会自动换行) 107 | fill=\procfillcolor, % 填充色 108 | }, 109 | % 判断框样式 110 | test/.style={base, % 基础样式 111 | diamond, % 菱形边框 112 | aspect=2.5, % 长高比例 113 | text width=\testtxtwd, % 最大文本宽度(超过会自动换行) 114 | fill=\testfillcolor, % 填充色 115 | }, 116 | % 输入/输出框样式 117 | io/.style={base, % 基础样式 118 | trapezium, % 平行四边形 119 | trapezium left angle=70, % 平行四边形左倾角 120 | trapezium right angle=110, % 平行四边形右倾角 121 | text width=\iotxtwd, % 最大文本宽度(超过会自动换行) 122 | fill=\iofillcolor, % 填充色 123 | }, 124 | % 开始/结束框样式 125 | term/.style={proc, % 基于proc样式 126 | rounded corners=2.0mm, % 为矩形添加圆角属性 127 | text width=\termtxtwd, % 最大文本宽度(超过会自动换行) 128 | fill=\termfillcolor, % 填充色 129 | }, 130 | % 流程连接点样式 131 | connector/.style = {draw, % 绘制边框 132 | circle, % 圆形 133 | node distance=3cm, % 节点间距 134 | }, 135 | % 绕接连线点样式(不相交的两个交汇路径) 136 | connect/.style args={(#1) to (#2) over (#3) by #4}{ 137 | insert path={ 138 | let \p1=($(#1)-(#3)$), \n1={veclen(\x1,\y1)}, 139 | \n2={atan2(\y1,\x1)}, \n3={abs(#4)}, \n4={#4>0 ?-180:180} in 140 | (#1) -- ($(#1)!\n1-\n3!(#3)$) arc (\n2:\n2+\n4:\n3) -- (#2) 141 | } 142 | }, 143 | % coord结点样式(用于布置流程线连接点) 144 | coord/.style={coordinate, % 笛卡尔坐标系 145 | %on chain, % 沿布局方向绘制 146 | %on grid, % 沿网格布局 147 | node distance=6mm and 25mm, % 节点间距 148 | }, 149 | % nmark结点样式(用于布置调试坐标标记点) 150 | nmark/.style={draw, % 绘制边框 151 | cyan, % 青色 152 | circle, % 圆形 153 | font={\sffamily\bfseries}, % 字体 154 | }, 155 | % ------------------------------------------------- 156 | % 无箭头连线样式 157 | lnorm/.style={line width = \flowlinewd, % 线宽 158 | draw, % 绘制 159 | \normcolor, % 颜色 160 | }, 161 | lfree/.style={line width = \flowlinewd, 162 | draw, 163 | \freecolor, 164 | }, 165 | lcong/.style={line width = \flowlinewd, 166 | draw, 167 | \congcolor, 168 | }, 169 | % 流程线实心交点样式 170 | dotnorm/.style={draw, % 绘制 171 | fill = \normcolor, % 填充颜色 172 | \normcolor, % 颜色 173 | }, 174 | dotfree/.style={draw, 175 | fill = \freecolor, 176 | \freecolor, 177 | }, 178 | dotcong/.style={draw, 179 | fill = \congcolor, 180 | \congcolor, 181 | }, 182 | % 流程线空心交点样式 183 | cdotnorm/.style={draw, % 绘制 184 | \normcolor, % 颜色 185 | }, 186 | cdotfree/.style={draw, 187 | \freecolor, 188 | }, 189 | cdotcong/.style={draw, 190 | \congcolor, 191 | }, 192 | % 带箭头连线样式 193 | norm/.style={line width = \flowlinewd, % 线宽 194 | -{Stealth[length=\stealthlen, % 箭头长度 195 | width=\stealthwd, % 箭头宽度 196 | ] 197 | }, 198 | draw, % 绘制 199 | \normcolor, % 颜色 200 | }, 201 | free/.style={line width = \flowlinewd, 202 | -{Stealth[length=\stealthlen, 203 | width=\stealthwd, 204 | ] 205 | }, 206 | draw, 207 | \freecolor, 208 | }, 209 | cong/.style={line width = \flowlinewd, 210 | -{Stealth[length=\stealthlen, 211 | width=\stealthwd, 212 | ] 213 | }, 214 | draw, 215 | \congcolor, 216 | }, 217 | % 斜体字样式 218 | it/.style={font={\small\itshape}}, 219 | } 220 | %% 判断是否为宏包传入了debug参数以打开调试功能,若没有传入debug参数,则关闭调试功能。 221 | \ifflowchart@debug 222 | % 设置一个用于调试的标记符号图层,注意确保这一图层位于顶层 223 | \pgfdeclarelayer{marx} 224 | \pgfsetlayers{main,marx} 225 | \newcommand{\cmark}[2][]{% 226 | \begin{pgfonlayer}{marx} 227 | \node [nmark] at (c#2#1) {#2}; 228 | \end{pgfonlayer}{marx} 229 | } 230 | \else 231 | \newcommand{\cmark}[2][]{\relax} 232 | \fi 233 | \endinput 234 | %% 235 | %% End of file `tikz-flowchart.sty'. 236 | --------------------------------------------------------------------------------