4

I am trying to draw several parallel arrows between the same nodes, to get roughly this result:

Desired result

What I would need is a hypothetical perpendicular shift key, which would shift the edge along its perpendicular. Using xshift works for the vertical lines, but not the horizontal ones, and vice versa for yshift.

I tried using decorate,decoration={lineto,raise=0.1cm}, but it seems to have no effect on the path. It kinda works with decorate,decoration={brace, amplitude=0,raise=0.1cm}, but it feels a bit clunky, and the arrow heads are all pointing upwards:

Result with brace decoration (the arrowheads all point upwards)

@Torbjørn T. mentionned this very similar question, which gets the line distance and arrowheads right, but alters the line length (the lines start and end near the nodes' centers, instead of starting near their borders):

The red and blue lines start near the node's center

Here's the code for the brace version:

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

I'm looking for a solution that can be used simply as a style on the whole path, and doesn't require knowing the angle of the line where it is used.

3

Defining a custom path decoration seems to work, although I'm not sure I did everything as it should, so bugs may arise in corner cases.

Result using the "simple line" decoration

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.