A previous version of this answer explained the paths.ortho
library that was published in my pgf
repo on GitHub. The library is now part of my tikz-ext
package which should be used instead (and has a proper manual).
The ext.paths.ortho
library provides
- the path operations
r-ud
, r-rl
, r-du
and r-lr
, they can be used like --
or -|
for example and
- the keys
udlr distance
as well as for every operator one <operator> distance
, which sets the distance between the middle part of the line and the nearest node.
Furthermore, nodes/coordinates can be placed at any position. Similar to the |-
and -|
operators, the corner points lie at 0.25
and 0.75
; this can be set to 1/<n>
and (<n>-1)/<n>
with pacing=<n>
, i.e. using spacing=3
sets the corner at 0.3333
and 0.6667
. The default is 4
.
There’s also the boolean only middle
which sets the corner points at 0
and 1
respectively.
More of this is explained in my answer to Vertical and horizontal lines in pgf-tikz.
In your example, all you need to do after loading the library is
\path [line] (BLOCK3) r-rl (BLOCK1);
Code
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning, ext.paths.ortho}
\tikzset{
block/.style={rectangle,draw,minimum size=1cm},
line/.style={draw, -latex},
}
\begin{document}
\begin{tikzpicture}[node distance = 1cm, auto]
% Place nodes
\node [block] (BLOCK1) {a};
\node [block, below= of BLOCK1] (BLOCK2) {b};
\node [block, below=2cm of BLOCK2, node distance=1cm] (BLOCK3) {c};
% Draw edges
\path [line] (BLOCK1) -- (BLOCK2);
\path [line] (BLOCK2) -- (BLOCK3);
\path [line] (BLOCK3) r-rl (BLOCK1);
\end{tikzpicture}
\begin{tikzpicture}[
node distance = 1cm,
/utils/temp/.style={#1/.style={to path={r-#1(\tikztotarget)\tikztonodes}}},
/utils/temp/.list={ud, rl, du, lr}]
\node [block] (a) {a};
\node [block, below=of a] (b) {b};
\node [block, right=of a] (c) {c};
\node [block, below=of c] (d) {d};
\path[line, very thick] (a) edge[ud] (c)
(c) edge[rl] (d)
(d) edge[du] (b)
(b) edge[lr] (a);
\path[line, green, thick, ortho/udlr distance=0.25cm] (a) edge[du] (c)
(c) edge[lr] (d)
(d) edge[ud] (b)
(b) edge[rl] (a);
\draw[red] (a) r-ud (c) r-rl (d) r-du (b) r-lr (a);
\end{tikzpicture}
\end{document}
Output 1