是否可以更改下面代码中的输出箭头,以使其不与矩形重叠?
\documentclass[standalone]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,decorations.markings,arrows}
\begin{document}
\begin{tikzpicture}[font=\small]
\tikzset{block/.style={draw, rectangle, line width=2pt, minimum height=3em,
minimum width=5em, outer sep=0pt}}
\tikzset{vecArrow/.style={
line width=1pt,
decoration={
markings,mark=at position 1 with {
\arrow[scale=2.5,line width=0.4pt] {open triangle 60}
}
},
double distance=4pt, shorten >= 13pt,
preaction = {decorate},
postaction = {draw,line width=4pt, white,shorten >= 10pt}
}}
\node [block] (A) {A};
\node[coordinate,right=2cm of A](B){};
\draw[vecArrow](A) -- node[above,align=center]{}(B);
\end{tikzpicture}
\end{document}
答案1
两种可能的解决方案:
您可以加载该
backgrounds
库,然后将箭头括在里面\begin{scope}[on background layer] ... \end{scope}
。或者,也许最好的解决方案是,您可以将其添加
shorten <= \pgflinewidth,
到vecArrow
样式定义中。箭头将自动缩短以适应节点边框的宽度。
两种情况下的结果如下:
答案2
最简单的解决方案是在最后绘制最上面的内容。在这种情况下,由于您将节点相对于其他节点放置,因此您可以“覆盖”已经绘制的内容:
\documentclass[tikz, border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{
positioning,
decorations.markings,
arrows
}
\tikzset{
block/.style={
draw,
rectangle,
line width=2pt,
minimum height=3em,
minimum width=5em,
outer sep=0pt
},
vecArrow/.style={
line width=1pt,
decoration={
markings,
mark=at position 1 with {
\arrow[scale=2.5,line width=0.4pt] {open triangle 60}
}
},
double distance=4pt,
shorten >=13pt,
preaction={decorate},
postaction={
draw,
line width=4pt,
white,
shorten >= 10pt
},
},
}
\begin{document}
\begin{tikzpicture}[font=\small]
\node [block] (A) {};
\node [coordinate, right=2cm of A] (B) {};
\draw[vecArrow](A) -- (B)
node [pos=1, anchor=west] {Anders};
\node [block] at (A) {A};
\end{tikzpicture}
\end{document}
另外,也可以将节点放在命令末尾\draw
,如上所示。
答案3
您可以在节点通过墨水绘制之前绘制路径append after command
。
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,decorations.markings,arrows}
\begin{document}
\begin{tikzpicture}[font=\small]
\tikzset{block/.style={draw, rectangle, line width=2pt, minimum height=3em,
minimum width=5em, outer sep=0pt}}
\tikzset{vecArrow/.style={
line width=1pt,
decoration={
markings,mark=at position 1 with {
\arrow[scale=2.5,line width=0.4pt] {open triangle 60}
}
},
double distance=4pt, shorten >= 13pt,
preaction = {decorate},
postaction = {draw,line width=4pt, white,shorten >= 10pt}
}}
\draw[vecArrow]
node [block,append after command={coordinate[right = 2cm of A] (B) {(A) -- (B)}}]
(A) {A};
\end{tikzpicture}
\end{document}
这给出了其他答案中给出的相同图片