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).
With the 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:
- Zig-Zag
- Zig-Zig
r-ud
,
r-du
,
r-lr
and
r-rl
.
The following keys exist (when these are used directly with the path operation, the prefix ortho/
should be dropped, e.g. -|-[ratio=.3]
).
ortho/spacing=<ratio>
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.
ortho/distance=<distance>
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 true
)
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 true
.
New timers are setup for both the Zig-Zag and the Zig-Zig connections, these can be configured through the following keys.
ortho/spacing=<number>
(default 4
)
This affects the the position of the kinks that will be at 1/<number>
(default 0.25) and <number>
−1/<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.
When <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 ortho/spacing=0
.
The Zig-Zig connections are explained on my answer to How to draw a return arrow from node-3 to node-1.
For to
and edge
connections the keys
horizontal vertical horizontal
for -|-
and
vertical horizontal vertical
for |-|
amongst others are defined. Previously, I've used |-|
and -|-
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
\tikzset{ortho/install shortcuts}
amongst others.
Code (Question)
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{ext.paths.ortho}
\begin{document}
\begin{tikzpicture}[thick, ->]
\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 );
\begin{scope}[yshift=-1.5cm, ortho/ratio=.2]
\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 );
\end{scope}
\end{tikzpicture}
\end{document}
Output (Question)

\begin{tikzpicture} \draw (0,0) node(a) [draw] {A} (3,1) node(b) [draw] {B}; \draw (a.east) -- ++(1,0) |- (b.west); \end{tikzpicture}