Considering the following picture:
I would like to connect the two blue paths in order to obtain the red path like in the following picture:
But I would like a solution where I don't have to know the horizontal length of the red path, so Tikz will automatically calculate the good length instead of me.
MWE
I tried something with coordinates but I obtain this result (I'm not able to "shift" the coordinates (A) and (B) vertically):
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*{\myDistance}{1}%
\begin{document}
\begin{tikzpicture}
% Preliminary node positionning
\draw (0,0) node[rectangle,draw,minimum width=\myDistance] (Nod0) {Node 0}%
($ (Nod0.north west)!0.2\myDistance!(Nod0.north east) $) -- ++(0,2*\myDistance)%
-- ++(\myDistance,0)%
node[rectangle,draw,minimum width=\myDistance cm,anchor=west] (Nod1) {Node 1}%
(Nod1.east) -- ++(\myDistance,0)%
node[rectangle,draw,minimum width=\myDistance cm,anchor=west] (Nod2) {Node 2}%
;%
% Two paths to connect
\draw[blue] ($ (Nod0.north west)!0.8\myDistance!(Nod0.north east) $) -- ++(0,\myDistance);%
\draw[blue] ($ (Nod1) !.5! (Nod2) $) -- ++(0,-\myDistance);%
\coordinate (A) at ($ (Nod0.north west)!0.8\myDistance!(Nod0.north east) $) +(0,\myDistance);
\coordinate (B) at ($ (Nod1) !.5! (Nod2) $) +(0,-\myDistance);%
\draw[red] (A) -- (B);%
\end{tikzpicture}
\end{document}
Why I don't want "absolute coordinates" ?
Because I want this graph to be easily modifiable, for example if I want to change the vertical and horizontal distance between Node 0 and Node 1, I just have to change the \myDistance value and everything will be automatically adapted, no need to manually repositioning the blue paths for example because everything is positioned relatively to Node 0.




+(…)isn't part of the coordinate specification, it's just a move to. You'll need to pull that into the coordinate specification of the coordinate. For example($ (Nod1) !.5! (Nod2) + (0,-\myDistance) $). Though, as you are already at these points in the previous paths, just defining the coordinates there is much easier. – Qrrbrbirlbel Feb 24 '23 at 08:03|-and-|as well as something like|-|. – Qrrbrbirlbel Feb 24 '23 at 08:38tikz-extisn't a LaTeX package, it's a CTAN/TeXLive/MikTeX package (I don't like it either). You just need to load the library\usetikzlibrary{ext.paths.portho}. – Qrrbrbirlbel Feb 24 '23 at 09:13