我尝试在相同的节点之间绘制几个平行箭头,以大致获得以下结果:
我需要的是假想的perpendicular shift
键,它可以沿垂直方向移动边缘。使用xshift
适用于垂直线,但不适用于水平线,反之亦然yshift
。
我尝试使用decorate,decoration={lineto,raise=0.1cm}
,但似乎对路径没有影响。它有点适用于decorate,decoration={brace, amplitude=0,raise=0.1cm}
,但感觉有点笨重,箭头都指向上方:
@Torbjørn T. 提到这个非常相似的问题,它使线距和箭头正确,但改变了线的长度(线的起点和终点都在节点的中心附近,而不是在节点的边界附近):
以下是该版本的代码brace
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,decorations.pathreplacing}
\begin{document}
\tikzset{
rel1/.style={->, red, decorate,decoration={brace, amplitude=0,raise=0.1cm}},
rel2/.style={->, green, },
rel3/.style={->, blue, decorate,decoration={brace, amplitude=0,raise=-0.1cm}}
}
\begin{tikzpicture}
\node (Z) at (0,0) {0};
\node (A) at (0,1) {A};
\node (B) at (1,1) {B};
\node (C) at (1,0) {C};
\draw[rel1] (Z) to (A);
\draw[rel1] (Z) to (B);
\draw[rel1] (Z) to (C);
\draw[rel2] (Z) to (A);
\draw[rel2] (Z) to (B);
\draw[rel2] (Z) to (C);
\draw[rel3] (Z) to (A);
\draw[rel3] (Z) to (B);
\draw[rel3] (Z) to (C);
\end{tikzpicture}
\end{document}
我正在寻找一种可以简单地用作整个路径上的样式的解决方案,并且不需要知道使用它的线的角度。
答案1
定义自定义路径装饰似乎有效,尽管我不确定我是否按照应该的方式做了所有事情,因此在极端情况下可能会出现错误。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,decorations.pathreplacing}
\pgfdeclaredecoration{simple line}{start}
{
\state{start}[width = +0pt,
next state=step]{
\pgfpathmoveto{\pgfpoint{0pt}{0pt}}
}
\state{step}[auto end on length = 3pt,
auto corner on length = 3pt,
width=+1pt]
{
\pgfpathlineto{\pgfpoint{1pt}{0pt}}
}
\state{final}
{}
}
\begin{document}
\tikzset{
rel1/.style={->, red, decorate,decoration={simple line, raise=0.1cm}},
rel2/.style={->, green, },
rel3/.style={->, blue, decorate,decoration={simple line, raise=-0.1cm}}
}
\begin{tikzpicture}
\node (Z) at (0,0) {0};
\node (A) at (0,1) {A};
\node (B) at (1,1) {B};
\node (C) at (1,0) {C};
\draw[rel1] (Z) to (A);
\draw[rel1] (Z) to (B);
\draw[rel1] (Z) to (C);
\draw[rel2] (Z) to (A);
\draw[rel2] (Z) to (B);
\draw[rel2] (Z) to (C);
\draw[rel3] (Z) to (A);
\draw[rel3] (Z) to (B);
\draw[rel3] (Z) to (C);
\end{tikzpicture}
\end{document}