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).
ext.paths.ortho library that is possible.
It works by re-writing and intercepting the main TikZ parser. (Which is also the reason this may possibly break with an TikZ update or another library but I hope it won't.)
This library introduces six path operators:
The following keys exist (when these are used directly with the path operation, the prefix
ortho/ should be dropped, e.g.
This sets the ratio for the middle part part of the Zig-Zag connection. Values under 0 and over 1 will lead to lines that look more like the Zig-Zig paths.
Instead of ratio an absolute distance can be used instead, this will be measured from the starting point when
<distance> ≥ 0 and from the targeting point otherwise.
ortho/from center=<true or false> (default
When nodes get connected the placement of the middle part of the Zig-Zag and the Zig-Zig (see below) connections will be calculated from the border of these nodes. The middle part of the connections will be calculated from the nodes’ center if this key is set to
New timers are setup for both the Zig-Zag and the Zig-Zig connections, these can be configured through the following keys.
This affects the the position of the kinks that will be at 1/
<number> (default 0.25) and
<number> (default 0.75). The position 0.5 will always be at the center of the middle part. Positions 0.0 and 1.0 will be at the start and at the end respectively.
<number> is set to
0 the position
-1 will be at the start,
0 will be at the first kink,
1 will be at the second kink,
2 will be at the end and
0.5 will still be the center of the middle part.
ortho/middle 0 to 1 is an alternative to
The Zig-Zig connections are explained on my answer to How to draw a return arrow from node-3 to node-1.
edge connections the keys
horizontal vertical horizontal for
vertical horizontal vertical for
amongst others are defined. Previously, I've used
-|- for these shortcuts but they conflict with
arrows specification which is why these are not defined by default anymore. However, they can easily be defined by
\draw[blue] (2.1, 1.1) |-| (1.1, 0.1);
\draw (2 , 1 ) -|- (1 , 0 );
\draw[blue] (3.1, 0.1) |-| (4.1, 1.1);
\draw (3 , 0 ) -|- (4 , 1 );
\draw[red] (2.1, 1.1) |-| (1.1, 0.1);
\draw[orange] (2 , 1 ) -|- (1 , 0 );
\draw[red] (3.1, 0.1) |-|[ratio=.8] (4.1, 1.1);
\draw[orange] (3 , 0 ) -|-[ratio=.8] (4 , 1 );