Tikz Edge: Distance from other nodes?
There are probably various approaches to this. This example shows one that I frequently use.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\tikzstyle{bordered} = [draw,thick,inner sep=5,minimum size=10,minimum width=100,font=\sffamily]
\tikzstyle{arrow} = [thick,-latex,font=\sffamily]
\node [] (init) {};
\node [bordered,below=of init] (image) {App Image};
\node [bordered,below=of image] (running) {Running Container};
\node [bordered,below=of running] (stopped) {Persisted Container};
\draw [arrow] (init) -- (image) node [midway,right] {Install};
\draw [arrow] (image) -- (running) node [midway,right] {Start};
\draw [arrow] (running) -- (stopped) node [midway,right] {Terminate or Kill};
\draw [arrow] ($(stopped.west)+(0,2pt)$) --
++(-1em,0) --
($(running.west)+(-1em,0)$)
node [midway,right] {Start} --
(running.west);
\draw [arrow] ($(stopped.west)+(0,-2pt)$) --
++(-2em,0) --
($(image.west)+(-2em,0)$)
node [midway,left] {Reset} --
(image.west) ;
\end{tikzpicture}
\end{document}
Somewhat simpler variant using the perpendicular syntax (|-
or -|
):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\tikzstyle{bordered} = [draw,thick,inner sep=5,minimum size=10,minimum width=100,font=\sffamily]
\tikzstyle{arrow} = [thick,-latex,font=\sffamily]
\node [] (init) {};
\node [bordered,below=of init] (image) {App Image};
\node [bordered,below=of image] (running) {Running Container};
\node [bordered,below=of running] (stopped) {Persisted Container};
\draw [arrow] (init) -- (image) node [midway,right] {Install};
\draw [arrow] (image) -- (running) node [midway,right] {Start};
\draw [arrow] (running) -- (stopped) node [midway,right] {Terminate or Kill};
\draw [arrow]
(stopped.west) ++ (up:2pt)
-- ++(left:1em)
|- (running.west)
node[pos=0.25,right]{Start} ;
\draw [arrow]
(stopped.west) ++ (down:2pt)
-- ++(left:2em)
|- (image.west)
node[pos=0.25,left]{Reset};
\end{tikzpicture}
\end{document}
A PSTricks solution:
\documentclass{article}
\usepackage{pstricks}
\usepackage{xfp}
% parameters
\def\boxWidth{3.4}
\def\boxHeight{0.7}
\def\separation{1}
\def\arrow{0.4}
% simplifies notation
\def\constA#1#2{\fpeval{#1*\boxHeight+#2*\separation}}
\def\constB#1{\fpeval{1+#1*\arrow}}
\def\constC#1{\fpeval{\constB{2}+#1*\boxWidth}}
\begin{document}
\psset{arrows = ->}
\begin{pspicture}(\fpeval{1+2*\arrow+max(\boxWidth,\boxWidth/2+2.85)},
\fpeval{3*(\boxHeight+\separation)})
\psline(\constC{0.5},\constA{3}{3})(\constC{0.5},\constA{3}{2})
\uput[r](\constC{0.5},\constA{2.5}{3}){Install}
\psframe(\constB{2},\constA{2}{2})(\constC{1},\constA{3}{2})
\rput(\constC{0.5},\constA{2.5}{2}){App Image}
\psline(\constC{0.5},\constA{2}{2})(\constC{0.5},\constA{2}{1})
\uput[r](\constC{0.5},\constA{2}{1.5}){Start}
\psframe(\constB{2},\constA{1}{1})(\constC{1},\constA{2}{1})
\rput(\constC{0.5},\constA{1.5}{1}){Running Container}
\uput[r](\constC{0.5},\constA{1}{0.5}){Terminate or Kill}
\psline(\constC{0.5},\constA{1}{1})(\constC{0.5},\constA{1}{0})
\psframe(\constB{2},0)(\constC{1},\constA{1}{0})
\rput(\constC{0.5},\constA{0.5}{0}){Persisted Container}
\psline(\constB{2},\fpeval{1/3*\boxHeight})%
(1,\fpeval{1/3*\boxHeight})%
(1,\constA{2.5}{2})%
(\constB{2},\constA{2.5}{2})
\uput[l](1,\constA{1.5}{1}){Reset}
\psline(\constB{2},\fpeval{2/3*\boxHeight})%
(\constB{1},\fpeval{2/3*\boxHeight})%
(\constB{1},\constA{1.5}{1})%
(\constB{2},\constA{1.5}{1})
\uput[r](\constB{1},\constA{1}{0.5}){Start}
\end{pspicture}
\end{document}
All you have to do is change the values of the parameters and the drawing will be adjusted accordingly.