7

I want to connect two nodes with one edge so that it bends twice.

For instance,

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}

        \node  (A) {A};
        \node  (B) [below of=A] {B};

        \draw[->] (A.east) -- (B.east);


    \end{tikzpicture}

\end{document}

will connect the two nodes with a straight line, but I want something like this

wiw

For this I would draw using -|- as a parameter to \draw, but that doesn't compile.

How can I get that line with two straight bends?

MJ Galram
  • 275
  • 2
  • 7

2 Answers2

7

One way to achieve that is to draw a straight line from A.east towards right of the lenght you need (for example to +(2em, 0)) and then a corner (|-) to B.east.

Please also look at Difference between "right of=" and "right=of" in PGF/TikZ.

\documentclass[border=4pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
    \begin{tikzpicture}
        \node  (A) {A};
        \node  (B) [below=3ex of A] {B};
        \draw[->] (A.east) -- +(2em, 0) |- (B.east);
    \end{tikzpicture}
\end{document}

enter image description here

CarLaTeX
  • 62,716
4

Since you are looking for a draw operator (such as -|-): there's the path.ortho library by Qrrbrbirlbel for easily drawing such edges, just use r-rl in this case:

\documentclass[tikz,border=4pt]{standalone}
\usetikzlibrary{positioning,paths.ortho}
\begin{document}
  \begin{tikzpicture}
    \node  (A) {A};
    \node  (B) [below=3ex of A] {B};
    \draw[->] (A.east) r-rl (B.east);
  \end{tikzpicture}
\end{document}

output

Stefan Kottwitz
  • 231,401