3

This is my code:

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
  \tikzstyle{node}=[rectangle,draw=black,text width=3cm,inner sep=0.2cm,text centered]
  \begin{tikzpicture}
    \node (A) [node] {A};
    \node (B) [node, below left=3cm of A] {B};
    \draw[->] (B.north) -- +(0,1cm) -- +(5cm,1cm) -- (A.south);
  \end{tikzpicture}
\end{document}

This renders as follows:

Now I obviously want to last line to be orthogonal. I know about stuff like (B.north|-A.south), but that is not applicable here. Changing the last -- to |- also does not yield the desired result, because the arrow then continues along the border of A. How can I make the last portion of the arrow orthogonal?

flyx
  • 2,051

2 Answers2

3

An alternative with using paths.ortho library developed by Qrrbrbirlbel for tikz and can be found in paths.ortho-hvvh.tex and paths.ortho-udlr.tex. By it the solution is very simple:

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{paths.ortho}
\usetikzlibrary{positioning}

\begin{document}
  \tikzstyle{node}=[rectangle,draw=black,text width=3cm,inner sep=0.2cm,text centered]
  \begin{tikzpicture}
    \node (A) [node] {A};
    \node (B) [node, below left=3cm of A] {B};
    \draw[thick,->] (B.north) |-| (A.south);
  \end{tikzpicture}
\end{document}

For more similar alternatives see answers here.

enter image description here

Zarko
  • 296,517
1

The Tikz operator |- is not a unique symbol for all these cases of orthogonal lines. It's very specific actually, and it describes a line that goes first vertical | and then horizontal -.

For this reason, this particular operator does not apply to your case, because the angle you're looking for is first horizontal, and then vertical. Therefore you should use -| instead:

\draw[->] (B.north) -- +(0,1cm) -| (A.south);

This will give you the orthogonal line to the center of the node. However, if you want the path to stop at the coordinate but still be orthogonal then you can do this:

\draw[->] (B.north) |- +(5cm,1cm) coordinate (a) -- (a|-A.south);

As you can see I removed the coordinate -- +(0,1cm) because it was redundant in this path.

Alenanno
  • 37,338
  • Okay, I think I forgot to state clearly that it is my intent for the line to end up exactly above the coordinate in the path. Your solution would draw the line to the middle of of As south border. – flyx Jul 17 '16 at 14:39
  • @flyx Where do you mean when you say "end up exactly above the coordinate in the path"? – Alenanno Jul 17 '16 at 14:41
  • You removed the +(5cm,1cm) in my path. But I intentionally added it so that the path will not end at A.south, but a bit left of it, exactly vertically above the waypoint. – flyx Jul 17 '16 at 14:57
  • @flyx The result is the same without that coordinate, because the last coordinate forces the path to stop at A.south anyways. Unless you want the path to not stop exactly at A.south. – Alenanno Jul 17 '16 at 14:58
  • @flyx Do you want something like the red path? See this image. – Alenanno Jul 17 '16 at 15:01
  • Yes, that is what I am searching for. Sorry for not making it clearer. – flyx Jul 17 '16 at 15:03
  • @flyx No problem. :) See edit. – Alenanno Jul 17 '16 at 15:08