TikZ-UML:如何将刻板印象置于关系旁边?

TikZ-UML:如何将刻板印象置于关系旁边?

有没有一种简单的方法可以将刻板印象放置在关系旁边而不是“上方”?(或者至少在刻板印象中添加白色背景?)

下面是一个例子来说明我的意思:

\documentclass[]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{tikz-uml}

\begin{document}
  \begin{tikzpicture}
    \umlclass[type=interface]{InterfaceA}{}{}
    \umlclass[y=-4]{ClassA}{}{}  
    \umlimpl[stereo=realizes, pos stereo=0.5]{ClassA}{InterfaceA}

    \umlclass[x=4, type=interface]{InterfaceB}{}{}
    \umlclass[x=4, y=-4]{ClassB}{}{}  
    \umlimpl[]{ClassB}{InterfaceB}
    \node[] at (3,-2) {<<realizes>>}; 
  \end{tikzpicture}  
\end{document}

在此处输入图片描述

谢谢!

答案1

修订方法xpatch

有关逻辑的描述,请参见下面的原始方法...这里,我只是设法通过它来合并xpatch

\documentclass[]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz-uml}
%%%%%%%%%%%%%%%%%%%%%%
\usepackage{xpatch}
\xpatchcmd{\umlrelation}{\stereotype}{\discardedstereotype}{}{}
\xpatchcmd{\umlrelation}{\stereotype}{\discardedstereotype}{}{}
\def\stereotypel{$\ll$\tikzumlRelationStereoType$\gg$%
   \noexpand\noexpand\noexpand\phantom{~$\ll$\tikzumlRelationStereoType$\gg$~}}%
\def\stereotyper{\noexpand\noexpand\noexpand\phantom{~$\ll$\tikzumlRelationStereoType%
  $\gg$~}$\ll$\tikzumlRelationStereoType$\gg$}%
\def\stereotypec{$\ll$\tikzumlRelationStereoType$\gg$}%
\def\stereotype{\if\relax\tikzumlRelationStereoType\relax\else%
  \csname stereotype\stereoalignment\endcsname\fi}%
\def\stereoalignment{c}
%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
 \begin{tikzpicture}
\def\stereoalignment{l}
    \umlclass[type=interface]{InterfaceA}{}{}
    \umlclass[y=-4]{ClassA}{}{}
    \umlimpl[stereo=realizes, pos stereo=0.5]{ClassA}{InterfaceA}

\def\stereoalignment{c}
    \umlclass[x=3, type=interface]{InterfaceA}{}{}
    \umlclass[x=3, y=-4]{ClassA}{}{}
    \umlimpl[stereo=realizes, pos stereo=0.5]{ClassA}{InterfaceA}

\def\stereoalignment{r}
    \umlclass[x=6, type=interface]{InterfaceA}{}{}
    \umlclass[x=6, y=-4]{ClassA}{}{}
    \umlimpl[stereo=realizes, pos stereo=0.5]{ClassA}{InterfaceA}

    \umlclass[x=9, type=interface]{InterfaceA}{}{}
    \umlclass[x=9, y=-4]{ClassA}{}{}
    \umlimpl[pos stereo=0.5]{ClassA}{InterfaceA}
  \end{tikzpicture}    
\end{document}

在此处输入图片描述

原始方法

我编辑了我的副本 tikz-uml.sty,因为我无法通过 使其工作\xpatchcmd。在宏下的样式中\umlrelation,有一段代码

  \ifthenelse{\equal{\tikzumlRelationStereoType}{}}{%
    \def\stereotype{}%
  }{%
    \def\stereotype{$\ll$\tikzumlRelationStereoType$\gg$}%
  }%

我将其改为:

  \ifthenelse{\equal{\tikzumlRelationStereoType}{}}{%
    \def\stereotype{}%
  }{%
    \def\stereotypel{$\ll$\tikzumlRelationStereoType$\gg$\noexpand\noexpand\noexpand\phantom{~$\ll$\tikzumlRelationStereoType$\gg$~}}%
    \def\stereotyper{\noexpand\noexpand\noexpand\phantom{~$\ll$\tikzumlRelationStereoType$\gg$~}$\ll$\tikzumlRelationStereoType$\gg$}%
    \def\stereotypec{$\ll$\tikzumlRelationStereoType$\gg$}%
    \def\stereotype{\csname stereotype\stereoalignment\endcsname}%
    \@ifundefined{stereoalignment}{\def\stereoalignment{c}}{}%
  }%

其中,\stereotype我并没有简单地定义,而是定义了\stereotypel\stereotypec\stereotyper来给出各种对齐方式。然后我重新定义为调用其中之一,具体\stereotype取决于宏的值为、或。如果用户未定义,则默认为。\stereoalignmentlcrc

妇女权利委员会:

\documentclass[]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{tikz-uml}

% I CHANGED THE \stereotype DEFINITION IN \umlrelation FROM THIS:
%  \ifthenelse{\equal{\tikzumlRelationStereoType}{}}{%
%    \def\stereotype{}%
%  }{%
%    \def\stereotype{$\ll$\tikzumlRelationStereoType$\gg$}%
%  }%
% TO THIS:
%  \ifthenelse{\equal{\tikzumlRelationStereoType}{}}{%
%    \def\stereotype{}%
%  }{%
%    \def\stereotypel{$\ll$\tikzumlRelationStereoType$\gg$\noexpand\noexpand\noexpand\phantom{~$\ll$\tikzumlRelationStereoType$\gg$~}}%
%    \def\stereotyper{\noexpand\noexpand\noexpand\phantom{~$\ll$\tikzumlRelationStereoType$\gg$~}$\ll$\tikzumlRelationStereoType$\gg$}%
%    \def\stereotypec{$\ll$\tikzumlRelationStereoType$\gg$}%
%    \def\stereotype{\csname stereotype\stereoalignment\endcsname}%
%    \@ifundefined{stereoalignment}{\def\stereoalignment{c}}{}%
%  }%

\begin{document}
  \begin{tikzpicture}
\def\stereoalignment{l}
    \umlclass[type=interface]{InterfaceA}{}{}
    \umlclass[y=-4]{ClassA}{}{}
    \umlimpl[stereo=realizes, pos stereo=0.5]{ClassA}{InterfaceA}

\def\stereoalignment{c}
    \umlclass[x=4, type=interface]{InterfaceA}{}{}
    \umlclass[x=4, y=-4]{ClassA}{}{}
    \umlimpl[stereo=realizes, pos stereo=0.5]{ClassA}{InterfaceA}

\def\stereoalignment{r}
    \umlclass[x=8, type=interface]{InterfaceA}{}{}
    \umlclass[x=8, y=-4]{ClassA}{}{}
    \umlimpl[stereo=realizes, pos stereo=0.5]{ClassA}{InterfaceA}
  \end{tikzpicture}    
\end{document}

在此处输入图片描述

相关内容