我的代码是
\documentclass{standalone}
\usepackage{pgf-umlcd}
\renewcommand{\unidirectionalAssociation}[4]
{
draw[umlcd style, ->] (#1) -- (#4)
node[near end, auto]{#2}
node[near end, auto,swap]{#3};
}
\begin{document}
\begin{tikzpicture}
\begin{abstractclass}[text width = 6cm]{FileStore}{0,0}
\attribute{$\sim$ com.alhelal.textpad}
\operation{+ orderFile(file : File) : EditableFile}
\operation[0]{\# createFile(file : File) : EditableFile}
\end{abstractclass}
\begin{class}[text width = 6cm,anchor = west,xshift = 5cm]{ProgrammFileFactory}{FileStore.east}
\inherit{FileStore}
\attribute{$\sim$ com.alhelal.textpad}
\operation{+ orderFile(file : File) : EditableFile}
\end{class}
\begin{class}[text width = 11cm, yshift = -2cm]{EditableFile}{ProgrammFileFactory.south}
\attribute{$\sim$ com.alhelal.textpad}
\attribute{+ languageBehavior : LanguageBehavior}
\operation{+ options : Options}
\operation{+ getCodeAreaFromTab(tb : Tab) : CodeArea}
\operation{+ saveFile(fileTabArrayList : ArrayList$<$FileTab$>$, option : Options)}
\operation{+ printFile(node : Node)}
\operation{+ toggleLineNumber(cd : CodeArea)}
\operation{+ setLanguageBehavior(langBehavior : LanguageBehavior)}
\operation{+ performRunCode(file : File)}
\operation{+ performBuildCode(file : File)}
\operation{+ performSetHighlightableText()}
\operation{+ performSetAutocompletableText()}
\end{class}
\begin{class}[text width = 3.5cm,anchor=north east,yshift = -2cm, xshift=-6cm]{TextFile}{EditableFile.south west}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\begin{class}[text width = 3.5cm,anchor=north east,yshift = -2cm, xshift = -1.5cm]{CFile}{EditableFile.south west}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\attribute{-path : String}
\end{class}
\begin{class}[text width=3.5cm,anchor=north west,yshift = -2cm,xshift=-3cm]{CplusFile}{EditableFile.south}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\begin{class}[text width = 3.5cm, anchor = north west, yshift = -2cm, xshift = -4cm]{JavaFile}{EditableFile.south east}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\begin{class}[text width = 3.5cm,yshift = -2cm,xshift = 1cm]{PythonFile}{EditableFile.south east}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\begin{class}[text width = 3.5cm, anchor = north west, yshift =-2cm,xshift = 5cm]{LaTeXFile}{EditableFile.south east}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\unidirectionalAssociation{ProgrammFileFactory}{}{$<<$instantiate$>>$}{EditableFile}
\node [above=3mm] at (current bounding box.north) {Factory Method Pattern}
\end{tikzpicture}
\end{document}
我在终端中运行它,pdflatex
结果是
答案1
的一般语法TikZ
是输入你想要绘制的内容,格式如下:
\command [ options ] ( location ) { stuff } ;
几乎所有东西都不需要。只有\command
(例如\draw
)和尾随;
以限制命令的范围,这很重要。您;
在最后一行忘记了这一点tikzpicture
,因此会出现此错误。并且您忘记了重命名 块\
开头的。 使用而不是draw
\unidirectionAssociation
\draw[umlcd style, ->] (#1) -- (#4)
draw[umlcd style, ->] (#1) -- (#4)
编译结果如下:
\documentclass{standalone}
\usepackage{pgf-umlcd}
\renewcommand{\unidirectionalAssociation}[4]
{
\draw[umlcd style, ->] (#1) -- (#4)% <------
node[near end, auto]{#2}
node[near end, auto,swap]{#3};
}
\begin{document}
\begin{tikzpicture}
\begin{abstractclass}[text width = 6cm]{FileStore}{0,0}
\attribute{$\sim$ com.alhelal.textpad}
\operation{+ orderFile(file : File) : EditableFile}
\operation[0]{\# createFile(file : File) : EditableFile}
\end{abstractclass}
\begin{class}[text width = 6cm,anchor = west,xshift = 5cm]{ProgrammFileFactory}{FileStore.east}
\inherit{FileStore}
\attribute{$\sim$ com.alhelal.textpad}
\operation{+ orderFile(file : File) : EditableFile}
\end{class}
\begin{class}[text width = 11cm, yshift = -2cm]{EditableFile}{ProgrammFileFactory.south}
\attribute{$\sim$ com.alhelal.textpad}
\attribute{+ languageBehavior : LanguageBehavior}
\operation{+ options : Options}
\operation{+ getCodeAreaFromTab(tb : Tab) : CodeArea}
\operation{+ saveFile(fileTabArrayList : ArrayList$<$FileTab$>$, option : Options)}
\operation{+ printFile(node : Node)}
\operation{+ toggleLineNumber(cd : CodeArea)}
\operation{+ setLanguageBehavior(langBehavior : LanguageBehavior)}
\operation{+ performRunCode(file : File)}
\operation{+ performBuildCode(file : File)}
\operation{+ performSetHighlightableText()}
\operation{+ performSetAutocompletableText()}
\end{class}
\begin{class}[text width = 3.5cm,anchor=north east,yshift = -2cm, xshift=-6cm]{TextFile}{EditableFile.south west}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\begin{class}[text width = 3.5cm,anchor=north east,yshift = -2cm, xshift = -1.5cm]{CFile}{EditableFile.south west}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\attribute{-path : String}
\end{class}
\begin{class}[text width=3.5cm,anchor=north west,yshift = -2cm,xshift=-3cm]{CplusFile}{EditableFile.south}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\begin{class}[text width = 3.5cm, anchor = north west, yshift = -2cm, xshift = -4cm]{JavaFile}{EditableFile.south east}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\begin{class}[text width = 3.5cm,yshift = -2cm,xshift = 1cm]{PythonFile}{EditableFile.south east}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\begin{class}[text width = 3.5cm, anchor = north west, yshift =-2cm,xshift = 5cm]{LaTeXFile}{EditableFile.south east}
\inherit{EditableFile}
\attribute{$\sim$ com.alhelal.textpad}
\end{class}
\unidirectionalAssociation{ProgrammFileFactory}{}{$<<$instantiate$>>$}{EditableFile}
\node [above=3mm] at (current bounding box.north) {Factory Method Pattern};% <-------
\end{tikzpicture}
\end{document}
我用 标记了我更改的行% <-------
。
编辑:我已更新上述代码以包含正确的重新定义,这要\unidirectionalAssociation
感谢@TorbjørnT 提供的澄清。