不久前,我在这里询问如何使 Tikz 图像上的一条线通过在另一条线上画弧线与它交叉。我正在寻找一种方法来清理我为工作中的某人创建的 Tikz 图像。有人能够将我链接到另一个非常有用的 Stackexchange 页面,该页面帮助我开始编写代码。但是,我注意到一个限制是创建的箭头上没有箭头。我提供的 MWE 是我最接近的尝试。当您排版代码时,您会看到,我能够得出的最接近答案仍然在线的交点下方留下一条线(隐藏这条线但在执行弯曲算法时仍然能够引用它会很有帮助),在这种情况下,在它上面留下一条线。我尝试过更改线条(即,另一条线是弧线),但它会从箭头中移除箭头。
我希望有人能在这里帮助我。改进这个项目真的很棒。
非常感谢,
抢
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes,arrows,shapes.multipart}
\begin{document}
\begin{tikzpicture}[node distance = 3.00cm, auto, ]
\tikzset{
decision/.style = {diamond, draw, fill=blue!20,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt},
block/.style = {rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em},
line/.style = {draw, -latex'},
cloud/.style = {draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em},
subroutine/.style = {draw,rectangle split, rectangle split horizontal,
rectangle split parts=3,minimum height=1cm,
rectangle split part fill={red!50, green!50, blue!20, yellow!50}},
connector/.style = {draw,circle,node distance=3cm,fill=yellow!20},
data/.style = {draw, trapezium,node distance=1.5cm,fill=olive!20}
}
\tikzset{
connect/.style args={(#1) to (#2) over (#3) by #4}{
insert path={
let \p1=($(#1)-(#3)$), \n1={veclen(\x1,\y1)},
\n2={atan2(\x1,\y1)}, \n3={abs(#4)}, \n4={#4>0 ?180:-180} in
(#1) -- ($(#1)!\n1-\n3!(#3)$)
arc (\n2:\n2+\n4:\n3) -- (#2)
}
},
}
\node [block,fill=green] (cs110) {\textbf{CS110} \emph{CS Class 1}};
\node[block,fill=blue,right of=cs110] (cs120){\textbf{CS120} \emph{CS Class 2}};
\node[block,fill=red, above of=cs120] (cs220) {Test 3};
\node[block,fill=orange,right of = cs220] (cs330) {Test 4};
\path[line, name path=120to220] (cs120) -- (cs220);
\path[line, name path = 110to330] (cs110) -- (cs330);
\path[name intersections={of=120to220 and 110to330, by=inter}];
\draw [connect=(cs120) to (cs220) over (inter) by 5pt];
%\path [name intersections={of=110to120 and 110to320,by=inter3}];
%\draw [connect=(math260) to (math310) over (inter3) by 7pt];
\end{tikzpicture}
\end{document}
答案1
也许我误解了这个问题,但我相信你所要做的就是将line
样式从直线\path
命令移到connect
路径。这将使直线不可见,并将line
样式(带有箭头)应用于带有圆弧的连接线:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes,arrows,shapes.multipart}
\begin{document}
\begin{tikzpicture}[node distance = 3.00cm, auto, ]
\tikzset{
decision/.style = {diamond, draw, fill=blue!20,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt},
block/.style = {rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em},
line/.style = {draw, -latex'},
cloud/.style = {draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em},
subroutine/.style = {draw,rectangle split, rectangle split horizontal,
rectangle split parts=3,minimum height=1cm,
rectangle split part fill={red!50, green!50, blue!20, yellow!50}},
connector/.style = {draw,circle,node distance=3cm,fill=yellow!20},
data/.style = {draw, trapezium,node distance=1.5cm,fill=olive!20}
}
\tikzset{
connect/.style args={(#1) to (#2) over (#3) by #4}{
insert path={
let \p1=($(#1)-(#3)$), \n1={veclen(\x1,\y1)},
\n2={atan2(\x1,\y1)}, \n3={abs(#4)}, \n4={#4>0 ?180:-180} in
(#1) -- ($(#1)!\n1-\n3!(#3)$)
arc (\n2:\n2+\n4:\n3) -- (#2)
}
},
}
\node [block,fill=green] (cs110) {\textbf{CS110} \emph{CS Class 1}};
\node[block,fill=blue,right of=cs110] (cs120){\textbf{CS120} \emph{CS Class 2}};
\node[block,fill=red, above of=cs120] (cs220) {Test 3};
\node[block,fill=orange,right of = cs220] (cs330) {Test 4};
\path[ name path=120to220] (cs120) -- (cs220);
\path[line, name path = 110to330] (cs110) -- (cs330);
\path[name intersections={of=120to220 and 110to330, by=inter}];
\draw [line, connect=(cs120) to (cs220) over (inter) by 5pt];
\end{tikzpicture}
\end{document}