我被卡住了,不知道该怎么解决。我想用 tkz-uml 包绘制一个 UML 类图。遗憾的是,我的结果并不理想。我尝试使用以下代码运行示例:
\documentclass[12pt,a4paper,article,oneside]{memoir}
%% Package
\usepackage[utf8]{inputenc}
\usepackage[backend=biber,bibencoding=utf8,sorting=nyt,language=ngerman, style=alphabetic]{biblatex}
\usepackage[breaklinks=true]{hyperref}
\usepackage[german]{babel}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage{tikz-uml}
\usepackage{graphicx}
\usepackage{subfloat}
\usepackage{eurosym}
\usepackage{bbding}
\usepackage{listings}
\usepackage{epstopdf}
\usepackage{pgfgantt}
\usepackage{wrapfig}
\usepackage{mathtools}
\usepackage{amsmath}
%% TiKz Stuff %%%
\usetikzlibrary{calc, decorations.pathmorphing,decorations.pathreplacing, fadings, shadings, shapes, arrows, positioning,patterns,automata}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{document}
\begin{tikzpicture}
\begin{umlpackage}{p}
\begin{umlpackage}{sp1}
\umlclass[template=T]{A}{n : uint \\ t : float}{}
\umlclass[y=-3]{B}{ d : double}{ \umlvirt{setB(b : B) : void} \\ getB() : B}
\end{umlpackage}
\begin{umlpackage}[x=10,y=-6]{sp2}
\umlinterface{C}{ n : uint \\ s : string}{}
\end{umlpackage}
\umlclass[x=2,y=-10]{D}{ n : uint }{}
\end{umlpackage}
\umlassoc[geometry=-|-, arg1=tata, mult1=*, pos1=0.3, arg2=toto, mult2=1, pos2=2.9, align2=left]{C}{B}
\umlunicompo[geometry=-|, arg=titi, mult=*, pos=1.7, stereo=vector]{D}{C}
\umlimport[geometry=|-, anchors=90 and 50, name=import]{sp2}{sp1}
\umlaggreg[arg=tutu, mult=1, pos=0.8, angle1=30, angle2=60, loopsize=2cm]{D}{D}
\umlinherit[geometry=-|]{D}{B}
\umlnote[x=2.5,y=-6, width=3cm]{B}{Kommentar zu classe B}
\umlnote[x=7.5,y=-2]{import-2}{blubber die blub}
\end{tikzpicture}
\end{document}
输出如下所示:
但它应该看起来与这个例子类似:
有人有什么建设性的想法吗?
谢谢!
答案1
tikz-uml
声明图层后加载。
代码
\documentclass[tikz]{standalone}
\usepackage{tikzscale}
\pgfdeclarelayer{background,foreground}
\pgfsetlayers{background,main,foreground}
\usepackage{tikz-uml}
\begin{document}
\begin{tikzpicture}
\begin{umlpackage}{p}
\begin{umlpackage}{sp1}
\umlclass[template=T]{A}{n : uint \\ t : float}{}
\umlclass[y=-3]{B}{ d : double}{ \umlvirt{setB(b : B) : void} \\ getB() : B}
\end{umlpackage}
\begin{umlpackage}[x=10,y=-6]{sp2}
\umlinterface{C}{ n : uint \\ s : string}{}
\end{umlpackage}
\umlclass[x=2,y=-10]{D}{ n : uint }{}
\end{umlpackage}
\umlassoc[geometry=-|-, arg1=tata, mult1=*, pos1=0.3, arg2=toto, mult2=1, pos2=2.9, align2=left]{C}{B}
\umlunicompo[geometry=-|, arg=titi, mult=*, pos=1.7, stereo=vector]{D}{C}
\umlimport[geometry=|-, anchors=90 and 50, name=import]{sp2}{sp1}
\umlaggreg[arg=tutu, mult=1, pos=0.8, angle1=30, angle2=60, loopsize=2cm]{D}{D}
\umlinherit[geometry=-|]{D}{B}
\umlnote[x=2.5,y=-6, width=3cm]{B}{Kommentar zu classe B}
\umlnote[x=7.5,y=-2]{import-2}{blubber die blub}
\end{tikzpicture}
\end{document}