2

I am creating a class diagram in pgf-umlcd. I have two classes, where there are one class aggregates two instances of another class. The obvious way to do this is below.

 \begin{figure}[ht]
   \begin{tikzpicture}[show background grid]
     \begin{class}[text width=8 cm]{A}{0,0}
     \end{class}

     \begin{class}[text width=8 cm]{B}{0,-2}
     \end{class}

     \aggregation{A}{first}{1}{B}
     \aggregation{A}{second}{1}{B}
   \end{tikzpicture}
 \end{figure}

This does not work well, as the arcs are drawn from the same location to the same location, so they are on top of each other, as is text labeling the arcs.

Is there a way to control the location of the edges without figuring out the arrow and line styles and using \draw?

1 Answers1

1

The following solves the problem.

\begin{figure}[ht]
  \begin{tikzpicture}[show background grid]
    \begin{class}[text width=8 cm]{A}{0,0}
    \end{class}

    \begin{class}[text width=8 cm]{B}{0,-2}
    \end{class}

    \aggregation{[xshift=2cm] A.south}{first}{1}{[xshift=-2cm] B.north}
    \aggregation{[xshift=-2cm] A}{second}{1}{[xshift=-2cm] B.north}
  \end{tikzpicture}
\end{figure}

The first and fourth arguments are passed to \draw inside parentheses, so node anchors can be used there (.south and .north) The [xshift] code sets that parameter for the current node and adjusts the position of that node in the path.

You need to specify .south and .north, as otherwise the path is drawn from the center of the class diagram. So this will be somewhat fragile if you are modifying the high level layout of the diagram.