箭头布局围绕课程,tikz uml

箭头布局围绕课程,tikz uml

我在 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}

基本上我无法让虚线绕过类。类似下面的内容

在此处输入图片描述

我以为指定以下内容可以让我实现我想要的布局,但它不起作用

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

答案1

我还没有尝试找出具体的作用tikz-uml,但你可以将 的arm1参数设置\umldep为适当的值。当你定义一个三段连接(如 )时-|-,第一段和最后一段的长度可以分别用arm1和 来设置arm2

我找不到在类边界上的某个随机位置启动依赖线的方法,因此我定义了两个辅助坐标,并将它们用作依赖线的起点。

代码输出

\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}

或者,由于您只是用特定样式 ( tikzuml dependency style) 绘制一条线,因此您可以这样做

\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);

相关内容