# Drawing a return path in a simple flow chart with Tikz

This is my first attempt at drawing anything Tikz, so bear with me:

I'm trying to draw a simple flowchart for a DSP algorithm, however i am stuck at properly drawing the loop return that it incorporates. As you can see below in my code example, i was only able to not make the return arrow intersect the blocks in my graph by defining a node to the left of a node in the center and drawing an arrow from bottom to that node and then from that node to the top.

Is there any way to connect the bottom and top nodes with one arrow and make it go through that node (or better yet, automatically make it avoid intersections with the existing blocks)?

As a minor note:

I was not able to get rid of the gap in the start and end points of the arrows, any help with that would also be appreciated.

Also, since i used linebreaks in the box text, the spacing between the boxes was off and i resorted to manually spacing them. Is there a better way to do this?

\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\tikzstyle{block} = [draw, rectangle,
minimum height=3em, minimum width=20em]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[auto, node distance=2cm,>=latex']

\node [input, name=input] {};
\node [block, below of=input, align=left] (reseter)
{$Betrag\ von\ X_{w}^{(i)}(mS, \omega)\ zur\ddot{u}cksetzen:$\\
$\hat{X}_{w}^{(i)}(mS, \omega)=|Y_{w}(mS, \omega)|\cdot e^{j\angle X_{w}^{(i)}(mS, \omega)}$};

\node [block, below= 1cm of reseter, align=left] (estimator)
{$Signalsch\ddot{a}tzung\ von\ X_{w}^{(i)}(mS, \omega):$\\
$x^{(i+1)}(n) = \frac {\displaystyle \sum \limits_{m=-\infty}^{\infty} w (mS-n) \cdot \hat x_w^{(i)} (mS,n) } {\displaystyle \sum \limits_{m=-\infty}^{\infty} w^2 (mS-n)}$};

\node [output, below=1.2cm of estimator] (output){};

\draw [->] (input) -- node {$x^{(i)}(n)$} (reseter);
\draw [->] (reseter) -- node [name=X] {$\hat{X}_{w}^{(i)}(mS, \omega)$} (estimator);
\draw [->] (estimator) -- node {$x^{(i+1)}(n)$} (output);

\node [above = 0.5cm of output] (fbs) {};
\node [below = 0.5cm of input] (fbe) {};
\node [left=5cm of X] (fb) {};
\draw [->] (fbs) -| (fb);
\draw [->] (fb) |- (fbe);
\end{tikzpicture}
\end{document}

• You were SO close! \draw [->] (fbs) -| (fb) |- (fbe); – John Kormylo Mar 4 '16 at 23:36
• Welcome! In addition to @JohnKormylo's comment: \coordinate [left=5cm of X] (fb); to avoid the gap. Similarly for fbs and fbe. Nodes always have some dimension unless you force them not to. Coordinates are automatically points. So they don't add any marginal separation around their contents as nodes do (even when there is no content). – cfr Mar 4 '16 at 23:39
• I'd do \draw [->] (fbs) -| ($(reseter.west)+(-1,0)$) |- (fbe); – Alenanno Mar 5 '16 at 0:18

This code will automatically space the blocks far enough apart to allow text between them. One can increase this space by increasing the inner sep or outer sep on the between nodes. I did have to fudge a little space to clear the left side of (reseter).

Note: Many of these changes are purely stylistic. There is nothing wrong with below of= or name=, I just prefer not to use them.

\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\begin{document}
\tikzset{input/.style=coordinate}
\tikzset{output/.style=coordinate}
\tikzset{block/.style={draw, rectangle,
minimum height=3em,
minimum width=20em}}
\tikzset{pinstyle/.style={pin edge={to-,thin,black}}}

\begin{tikzpicture}[auto, node distance=2cm,>=latex']

\node  (input) [input] {};

\node (fbe) [below right] at (input.south) {$x^{(i)}(n)$};

\node  (reseter)  [block, below, align=left] at (fbe.south west)
{$Betrag\ von\ X_{w}^{(i)}(mS, \omega)\ zur\ddot{u}cksetzen:$\\
$\hat{X}_{w}^{(i)}(mS, \omega)=|Y_{w}(mS, \omega)|\cdot e^{j\angle X_{w}^{(i)}(mS, \omega)}$};

\node (X) [below right] at (reseter.south) {$\hat{X}_{w}^{(i)}(mS, \omega)$};

\node (estimator) [block, below, align=left] at (X.south west)
{$Signalsch\ddot{a}tzung\ von\ X_{w}^{(i)}(mS, \omega):$\\
$x^{(i+1)}(n) = \frac {\displaystyle \sum \limits_{m=-\infty}^{\infty} w (mS-n) \cdot \hat x_w^{(i)} (mS,n) } {\displaystyle \sum \limits_{m=-\infty}^{\infty} w^2 (mS-n)}$};

\node (fbs) [below right] at (estimator.south) {$x^{(i+1)}(n)$};

\node (output) [output, below] at (fbs.south west) {};

\draw [->] (input) --  (reseter);
\draw [->] (reseter) --  (estimator);
\draw [->] (estimator) --  (output);

\coordinate (fb) at ($(estimator.west)+(-1em,0)$);
\draw [->] (fbs) -| (fb) |- (fbe);
\end{tikzpicture}
\end{document}


• \tikzstyle is deprecated. – cfr Mar 5 '16 at 1:05
• @cfr - Hadn't even noticed (and here I was searching the manual for input and output shapes). I guess I should set a good example. – John Kormylo Mar 5 '16 at 4:08
• @cfr Thanks for the heads up. I used an example for a control circuit from the net, guess i should start reading the manual. :-> – sobek Mar 5 '16 at 9:15
• Thank you for refactoring, John! This is exactly what i was after. Now for digesting the wisdom. :-) – sobek Mar 5 '16 at 9:33