我想|-
从分割的矩形行开始到右下方的节点绘制虚线箭头()。
我观察到,多条虚线可能会相互叠加以绘制一条直线。即使我设法实现了我想要的效果,当我移动初始矩形节点时,所有箭头都乱了套,我必须重新排列它们的位置,因为我在我的方法中嵌入了它们的网格位置。
我的代码:
\documentclass[5p,times]{elsarticle}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{
chains,
positioning,
shapes.geometric,
shapes
}
\begin{document}
\section{Example}
\noindent
\begin{tikzpicture}[
node distance = 4mm and 8mm,
arr/.style = {-Stealth, semithick},
C/.style = {circle, draw, font=\footnotesize},
N/.style = {draw, very thick,
font=\small, align=left,
inner sep=5pt},
data/.style={
draw,
rectangle split,
rectangle split parts=4,
text centered,
font=\scriptsize
}
]
\node [data,label=below:{test}] (n1) at (1,1) {
one
\nodepart{second} two
\nodepart{third} three
\nodepart{fourth} four
};
\node[
cylinder,draw,
shape border rotate=90,
semithick,
fill=white,
shape aspect=0.2,
font={\scriptsize\baselineskip=8pt},
inner xsep=1pt,
align=center,
below = of n1,
xshift=18mm,
] (n2) {Storage};
%
\draw[dashed,semithick] (n1.one east) -| (1.65 ,0) |- (n2.west);
\draw[dashed,semithick] (n1.40) -| (1.65 ,0) |- (n2.west);
\draw[dashed,semithick] (n1.three east) -| (1.65 ,0) |- (n2.west);
\end{tikzpicture}
\end{document}
输出:
想要的输出:
作为:
(*)--
(*)--|
(*)--|
(*) |
|--->(*)
答案1
我会将所有样式定义写入tikzpicture
选项(MWE 更加一致),定义aux
循环中绘制连接线的坐标并使用相对节点定位。
\documentclass[5p,times]{elsarticle}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
positioning,
shapes.geometric, shapes.multipart
}
\begin{document}
\section{Example}
\noindent%
\begin{tikzpicture}[
node distance = 4mm and 8mm,
data/.style = {rectangle split, rectangle split parts=4,
draw, semithick, font=\small},
disk/.style = {cylinder, draw, semithick,
shape border rotate=90,
shape aspect=0.2,
font=\small},
line/.style = {densely dashed, semithick}
]
\node [data,
label=below:{test}] (n1) {one
\nodepart{second} two
\nodepart{third} three
\nodepart{fourth} four
};
\coordinate[right=of n1.one east] (aux);
\node[disk,
below right = of n1.south -| aux] (n2) {Storage};
%
\foreach \x in {one , two , three }
\draw[line] (n1.\x east) -- (aux |- n1.\x east);
\draw[line] (aux) |- (n2.west);
\end{tikzpicture}
\end{document}
答案2
你应该只绘制一次每个路径段。也就是说,绘制一条从起点到终点的线,然后只绘制其他线的连接部分:
\documentclass[5p,times]{elsarticle}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{
chains,
positioning,
shapes.geometric,
shapes
}
\begin{document}
\section{Example}
\noindent
\begin{tikzpicture}[
node distance = 4mm and 8mm,
arr/.style = {-Stealth, semithick},
C/.style = {circle, draw, font=\footnotesize},
N/.style = {draw, very thick,
font=\small, align=left,
inner sep=5pt},
data/.style={
draw,
rectangle split,
rectangle split parts=4,
text centered,
font=\scriptsize
}
]
\node [data,label=below:{test}] (n1) at (1,1) {
one
\nodepart{second} two
\nodepart{third} three
\nodepart{fourth} four
};
\node[
cylinder,draw,
shape border rotate=90,
semithick,
fill=white,
shape aspect=0.2,
font={\scriptsize\baselineskip=8pt},
inner xsep=1pt,
align=center,
below = of n1,
xshift=18mm,
] (n2) {Storage};
\draw[dashed,semithick] (n1.one east) -| (1.65,0) |- (n2.west);
\draw[dashed,semithick] (n1.two east) -- (n1.two east -| 1.65,0);
\draw[dashed,semithick] (n1.three east) -- (n1.three east -| 1.65,0);
\end{tikzpicture}
\end{document}
替代方法:先画出三条线重叠的部分。也就是说,从三条线相交的坐标开始:
\draw[dashed,semithick] (n2.west) -| (1.65,0) |- (n1.one east);
\draw[dashed,semithick] (n2.west) -| (1.65,0) |- (n1.two east);
\draw[dashed,semithick] (n2.west) -| (1.65,0) |- (n1.three east);