标签:ips 压缩 边框 index.php 说明文档 type 最新 images 绘制
TikZ-UML宏包是用于绘制UML图形的,相较于我以前使用的pgf-umlcd宏包而言,他支持的图形种类更多,二者都是由tikz扩展而来。这里把使用方法与绘图例子记录下来,以备忘。% 51CTO陆巍的博客
\documentclass[oneside, AutoFakeBold]{article}
\usepackage{geometry} % 用于页面设置
% 设置为A4纸,并按照MSOffice的默认尺寸设置四周边距
\geometry{
a4paper,
left = 3.17cm,
right = 3.17cm,
top = 2.54cm,
bottom = 2.54cm
}
% 颜色支持
\usepackage[dvipsnames, svgnames, x11names]{xcolor}
% 汉字支持
\usepackage{xeCJK}
% 设置字体。注意顺序,第一个定义的就是默认字体
\setCJKfamilyfont{song}{方正书宋简体}
\newcommand{\song}{\CJKfamily{song}}
\setCJKfamilyfont{kaiti}{方正楷体简体}
\newcommand{\kaiti}{\CJKfamily{kaiti}}
\setCJKfamilyfont{heiti}{方正黑体简体}
\newcommand{\heiti}{\CJKfamily{heiti}}
% 绘图支持
\usepackage{tikz}
\usetikzlibrary{arrows}
% UML绘图支持
% tikz-uml宏包并不在texlive中,需要单独下载
% 下载后可放在自己定义的文件夹内,并在调用时指明完整路径
\usepackage{/mydata/latex_package/tikzuml/tikz-uml}
% 设置断字参数,数值越大,出现断字的情况越少
\hyphenpenalty = 1000
% ------------------ 开始 -------------------
\begin{document}
... % 正文
\end{document}
下面的示例代码放在正文部分即可。
示例一
\begin{center}
\begin{tikzpicture}
\umlsimpleclass[x = -4, y = 2, draw = purple]{Mock CheckWriter}{}{}
\umlsimpleclass[x = 0, y = 2, draw = purple]{PayrollTest}{}{}
\umlsimpleclass[x = 4, y = 2, draw = purple]{Mock Employee}{}{}
\umlinterface[x = -4, y = 0, draw = purple]{CheckWriter}{}{
+ writeCheck()
}
\umlsimpleclass[x = 0, y = 0, draw = purple]{Payroll}{}{}
\umlinterface[x = 4, y = 0, draw = purple]{Employee}{}{
+ claculatePay()\ + postPayment()
}
\umlinterface[x = 0, y = -3, draw = purple]{Employee Database}{}{
+ getEmployee()\ + putEmployee()
}
\umlsimpleclass[x = 0, y = -6, draw = purple]{Mock Employee Database}{}{}
\umluniassoc[draw = purple]{PayrollTest}{Mock CheckWriter}
\umluniassoc[draw = purple]{PayrollTest}{Mock Employee}
\umluniassoc[draw = purple]{PayrollTest}{Payroll}
\draw[draw = purple, -angle 45](PayrollTest.north) -- ++(0, 0.3) -- ++(6, 0) |- (Mock Employee Database);
\umluniassoc[draw = purple]{Payroll}{CheckWriter}
\umluniassoc[draw = purple]{Payroll}{Employee}
\umluniassoc[draw = purple]{Payroll}{Employee Database}
\umlinherit[draw = purple]{Mock CheckWriter}{CheckWriter}
\umlinherit[draw = purple]{Mock Employee}{Employee}
\umlHVdep[draw = purple]{Employee Database}{Employee}
\umlinherit[draw = purple]{Mock Employee Database}{Employee Database}
\end{tikzpicture}
\heiti\\[0.4cm] 图4.2 使用Mock Objects测试方法,解除了耦合的薪水支付应用模型\song
\end{center}
效果如下:
说明:
1) 配色方案:底色默认就是淡黄,边框色与线段颜色是用命令:draw=purple来设置的(默认是黑色),之所以选用这样的配色是受Rational Rose的影响。
2) 目前没有找到类名称自动换行的设置方法,只能是全部放在一行中了。(设置text width与双斜杠均无效。)
3) TikZ-UML是由tikz扩展而来,所以tikz中的很多功能在这里也可以用,例如上述例子中从PayrollTest到Mock Employee Database的线段绘制方式。
标签:ips 压缩 边框 index.php 说明文档 type 最新 images 绘制
原文地址:http://blog.51cto.com/14013986/2329523