You can do this with a to path
. The following solution is intended to highlight the steps that are needed. The solution can draw connections in any direction, not just vertical/horizontal connections, and therefore generalises all other solutions presented thus far.
Also note the solution doesn't include an animated picture, so you can focus on the provided output without any risk of being distracted by the animation:-)
.
The solution shows a nice application of the not-too-frequently used projection modifier ($(a)!(b)!(c)$), which projects the point (b) onto the infinite line through (a) and (c).
The reader may add their own favourite auxiliary keys for drawing a horizontal-vertical-horizontal connection, or a vertical-horizontal-vertical connection.
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
% The parsing is done relative to the key "/my connection/,
% which is not part of the user-defined API
\pgfkeys{/my connection/.cd,
% Save the angle value.
angle/.store in=\mycon@angle,
% Save the ratio value.
ratio/.store in=\mycon@ratio,
% The draw key triggers the drawing. Should be last.
draw/.style={/tikz/to path={
let % \n{a} is the angle.
\n{a}=\mycon@angle,
% \n{r} is the ratio.
\n{r}=\mycon@ratio,
% \p{s} is the start of the connection.
\p{s}=(\tikztostart),
% \p{t} is the target of the connection.
\p{t}=(\tikztotarget),
% \p{sa} is some point on the line from \p{s} in direction \n{a}.
\p{sa}=($(\p{s})+(\n{a}:1)$),
% \p{st} is some point on the line from \p{t} in direction \n{a}.
\p{st}=($(\p{t})+(\n{a}:1)$),
% \p{proj s} is the projection of \p{s} on the line through \p{t} and \p{st}.
\p{proj s}=($(\p{t})!(\p{s})!(\p{st})$),
% \p{proj t} is the projection of \p{t} on the line through \p{s} and \p{sa}.
\p{proj t}=($(\p{s})!(\p{t})!(\p{sa})$)
in % Second point of connection.
-- ($(\p{s})!\n{r}!(\p{proj t})$)
% Third point of connection.
-- ($(\p{proj s})!\n{r}!(\p{t})$)
% Last point of connection.
-- (\p{t})
\tikztonodes}}}
% The "connection" key is part of the user-defined API key.
% It has two sub-keys: ratio and angle, with default values 0.5
% and 0 respectively. We use the connection key to set the defaults,
% override the user-provided values for the keys (if any), and then
% draw the connection.
\tikzset{connection/.style={/my connection/.cd,ratio=0.5,angle=0,#1,draw}}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw (0,0) coordinate(a) node[anchor=north]{$a$}
(6,3) coordinate(b) node[anchor=south]{$b$};
\draw[->] (a) to[connection] (b);
\draw[blue,->] (b) to[connection={ratio=0.25,angle=30}] (a);
\draw[red,->] (a) to[connection={ratio=0.25,angle=90}] (b);
\end{tikzpicture}
\end{document}

\begin{tikzpicture} \draw (0,0) node(a) [draw] {A} (3,1) node(b) [draw] {B}; \draw (a.east) -- ++(1,0) |- (b.west); \end{tikzpicture}
– percusse Feb 21 '12 at 23:48