3

Consider the following piece of code:

\begin{tikzpicture} 
\umlsimpleclass[x=0,y=0]{Human}
\umlsimpleclass[x=10,y=0]{Pet}
\umlassoc[mult1=1, mult2=1..*, pos1=0.1, pos2=0.9]{Human}{Pet}
\end{tikzpicture}

I would like to add the word "owns" above the relation line between Human and Pet. I want the word to be in the middle of the line. The problem is that if I use any of "arg1", "arg2" or "arg" attributes of \umlassoc, it puts the word above the multiplicity (either at the right or at the left of the relation line, but not in the middle).

Does anyone know how I can do what I want ?

1 Answers1

5
  1. Give a name to the association using the name option; call it e.g. owns:

    \umlassoc[..., name=owns]{Human}{Pet}
    

    Then several positions will be defined along the path of the relation named owns-1, owns-2, .... In fact, for this simple path there is only the position in the middle called owns-1. For a path with several corners there are more. To find out which there are, either proceed by trial and error (by trying owns-1, owns-2 etc in turn) or read the docs of the tikz-uml package.

  2. Add \node statements to add labels at the points defined above. In you example use e.g.

    \node[above] at (owns-1) {owns};
    

enter image description here

\documentclass[border=2mm]{standalone}
\usepackage{tikz-uml}
\begin{document}
\begin{tikzpicture} 
\umlsimpleclass[x=0,y=0]{Human}
\umlsimpleclass[x=10,y=0]{Pet}
\umlassoc[mult1=1, mult2=1..*, pos1=0.1, pos2=0.9, name=owns]{Human}{Pet}
\node[above] at (owns-1) {owns};
\end{tikzpicture}
\end{document}
gernot
  • 49,614