I want to create a figure with TikZ:
I tried first with the following code (remark: Complete MWE on bottom):
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{2cm}};
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3] (A) |-( B);
\end{tikzpicture}
I created the two nodes A and B and draw the two pathes between them. But the 2nd one overwrites the first.
Then I tried to shift the 2nd path, but the the starting and end point are also shifted:
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{2cm}};
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3,transform canvas={shift={(-0.2,-0.2)}}] (A) |-( B); % shift complete path
\end{tikzpicture}
Then I tried to modify the start and end point with degrees (example now with three lines):
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{2cm}};
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3] (A.80) |-( B.190); %set target with angle
\path [draw,green, line width=3] (A.70) |-( B.200); %set target with angle
\end{tikzpicture}
This looks good (see my first image), but it is try and error to get the right degrees. I the node shape changes, the distance between two pathes changes and I have to look for another degree.
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{5cm}}; %modified node
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3] (A.80) |-( B.190); %set target with angle
\path [draw,green, line width=3] (A.70) |-( B.200); %set target with angle
\end{tikzpicture}
My last attempt was using an offset for start and end position:
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{2cm}};
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3] (A.north)+(0.2,0) |-( B.west)+(0,-0.2);
\end{tikzpicture}
To use the offset I must decide the start orientation (north, west...). And in my example the starting point is ok, but the 2nd part of the path is not shifted.
I also found TikZ parallel Edges between Nodes, but I found now way to use it.
Is there an easier way to create parallel pathes? I don't want to need try and error methods to find the correct positions. My last try with the offset seems to be the logical version, but there is a problem with the end position.
Heres my MWE:
\documentclass[]{scrartcl}
\usepackage{tikz}
% ----------------------------------------------------------------
\begin{document}
\tikzstyle{block} = [draw=black,very thick, rectangle, rounded corners]
\section{Problem: Pathes are overwritten}
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{2cm}};
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3] (A) |-( B);
\end{tikzpicture}
\section{Shift path}
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{2cm}};
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3,transform canvas={shift={(-0.2,-0.2)}}] (A) |-( B); % shift complete path
\end{tikzpicture}
\section{Set point with degrees}
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{2cm}};
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3] (A.80) |-( B.190); %set target with angle
\path [draw,green, line width=3] (A.70) |-( B.200); %set target with angle
\end{tikzpicture}
\subsection{But with other nodes}
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{5cm}}; %modified node
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3] (A.80) |-( B.190); %set target with angle
\path [draw,green, line width=3] (A.70) |-( B.200); %set target with angle
\end{tikzpicture}
\section{Use offsets}
\begin{tikzpicture}
\node [block] (A) at (0,0) {\rule{2cm}{2cm}};
\node [block] (B) at (5,5) {\rule{2cm}{2cm}};
\path [draw,red, line width=3] (A) |-( B);
\path [draw,blue, line width=3] (A.north)+(0.2,0) |- ( B.west)+(0,-0.2);
\end{tikzpicture}
\end{document}
% ----------------------------------------------------------------
\path … (A.north)+(0.2,0) |-( B.west)+(0,-0.2);
does not work because the line will be drawn only toB.west
and than a move about0.2
to the left will be happen. You need to do something like([xshift=-0.2] B.west)
instead.shorten
option to avoid wrong start/end point, when shifting the path.\path [draw,blue, line width=3] (A.north)+(0.2,0) |- ([yshift=-5] B.west);
to get a good looking result. Do you have an explanation, why I need a value 5 to get a similar y-distance for my 0.2-valuy in x-direction? (If I use a fix value like 2mm there is no difference between x and y). You may make an answer of your comment. There are good chances, that is will be my accepted answer.<len>
in[xshift=<len>]
and[yshift=<len>]
will not get automaticallycm
appended like in coordinates (butpt
), so you need to writeyshift=-0.2cm
in that regard, sorry. I won’t add an answer, because basically this is the same thing what Bertfried Fauser did in his answer (see also my comments there).