3

I've this code in tikz uml.

\documentclass[tikz,14pt,border=10pt]{standalone}
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{tikz-uml}
\usepackage{xcolor}
\usepackage{pgf-umlsd}
\usetikzlibrary{er}
\usetikzlibrary{decorations}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{positioning,calc}

\tikzstyle{int}=[draw, fill=blue!20, minimum size=3em]
\tikzstyle{init} = [pin edge={to-,thin,black}]

\begin{document}
\begin{tikzpicture} 
\umlclass[rectangle split parts=2,x=-4,y=3]{B} {
    \umlvirt{+ method() : void}} {
}

\umlclass[rectangle split parts=2,x=-2,y=-3]{C} {
    \umlvirt{+ method() : void}} {
}

\umlclass[rectangle split parts=2,x=-2,y=-5]{D}
{
    \umlvirt{+ method() : int}}
    {
}

\umlclass[rectangle split parts=2,x=-2,y=-9]{E} {
    \umlvirt{+ method() : void}
    }
    {
}

%%%%%%%%%%%%%%%%%
\umldep[geometry=-|-,anchor1=east,anchor2=east]{B}{E}
\umldep[geometry=-|-,anchor1=east,anchor2=east]{B}{D}
\umldep[geometry=-|-,anchor1=east,anchor2=east]{B}{C}

\end{tikzpicture}
\end{document}

And basically I can't manage to let the dashed lines to go around the classes. Something like the following

enter image description here

I thought that specifiying the following would've allowed me to achieve the layout I wanted to but it doesn't work

\umldep[geometry=-|-,anchor1=east,anchor2=east]{B}{E}
\umldep[geometry=-|-,anchor1=east,anchor2=east]{B}{D}
\umldep[geometry=-|-,anchor1=east,anchor2=east]{B}{C}
2

I haven't tried to find out exactly what tikz-uml does, but you can set the arm1 parameter of \umldep to appropriate values. When you define a three segment connection like -|-, the length of the first and last segment can be set with arm1 and arm2, respectively.

I couldn't find a way of starting the dependency line on some random position along the border of a class, so I defined two helper coordinates instead, and used those as the starting point of the dependency line.

output of code

\documentclass[
  tikz,
%  14pt, % not a valid option in standard classes (which standalone uses)
  border=10pt
]{standalone}
%\usepackage{verbatim} not used in this example
%\usepackage{tikz} loaded by tikz-uml
\usepackage{tikz-uml}
%\usepackage{xcolor} loaded by tikz
%\usepackage{pgf-umlsd} not used

% none of the remaining preamble is used
%\usetikzlibrary{er}
%\usetikzlibrary{decorations}
%\usetikzlibrary{shapes,arrows}
%\usetikzlibrary{shapes.misc}
%\usetikzlibrary{positioning,calc}

%\tikzset{ % recommended over \tikzstyle
%  int/.style={draw, fill=blue!20, minimum size=3em},
%  init/.style={pin edge={to-,thin,black}}
%}

\begin{document}
\begin{tikzpicture} 
\umlclass[rectangle split parts=2,x=-4,y=2]{B} {
    \umlvirt{+ method() : void}} {
}

\umlclass[rectangle split parts=2,x=-2,y=0]{C} {
    \umlvirt{+ method() : void}} {
}

\umlclass[rectangle split parts=2,x=-2,y=-3]{D}
{
    \umlvirt{+ method() : int}}
    {
}

\umlclass[rectangle split parts=2,x=-2,y=-5]{E} {
    \umlvirt{+ method() : void}
    }
    {
}

% define coordinates 5mm above/below the east point of B
\coordinate (B1) at ([yshift=5mm]B.east);
\coordinate (B2) at ([yshift=-5mm]B.east);


% note that B1 and B2 are used here
\umldep[geometry=-|-,anchor1=east,anchor2=east,arm1=4cm]{B1}{E}
\umldep[geometry=-|-,anchor1=east,anchor2=east,arm1=3.25cm]{B}{D}
\umldep[geometry=-|-,anchor1=east,anchor2=east,arm1=2.5cm]{B2}{C}

\end{tikzpicture}
\end{document}

Alternatively, as you're just drawing a line with a specific style (tikzuml dependency style), you could do

\draw [tikzuml dependency style] ([yshift=3mm]B.east) -- ++(4cm,0) |- (E.east);
\draw [tikzuml dependency style] (B.east) -- ++(3.25cm,0) |- (D.east);
\draw [tikzuml dependency style] ([yshift=-3mm]B.east) -- ++(2.5cm,0) |- (C.east);
| improve this answer | |
  • Does this work for other kind of relationships? like umlcompo for example and the others. – user8469759 Sep 5 '17 at 13:08
  • @user8469759 I would think so. Looks like all the different relations use the same underlying macro, \umlrelation. The only difference between them is that different styles are used. I.e. \umldep is basically \umlrelation[tikzuml dependency style], \umlcompo is basically \umlrelation[tikzuml composition style], etc. – Torbjørn T. Sep 5 '17 at 13:12
  • What's the meaning of arm1 and arm2? – user8469759 Sep 6 '17 at 10:03
  • @user8469759 Did you read the first paragraph of my answer? – Torbjørn T. Sep 6 '17 at 10:43
  • @user8469759 You can always delete your own comments I think, hover the cursor over a comment, and an "x" appears to the right of it. – Torbjørn T. Sep 6 '17 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.