How to draw a return arrow from node-3 to node-1

You can just add a line like:

\path [line] (BLOCK3) --++ (2cm,0cm) |- (BLOCK1);

This path starts at the BLOCK3 node. It then moves (--) to the point which has coordinates (2cm,0cm) relative to this point; hence one of the +s. The second + makes the resulting point the new point of reference. Without it the next part of the path would still be drawn "from" BLOCK3.

The next path description |- draws a right-angle path (vertical first, then horizontal) to BLOCK1. Had we used -| instead it would have been horizontal first, then vertical. Not that you would want that; I'm just including it for clarity.

output


The following answer consists of

  • tikzlibrarypaths.ortho.code.tex
  • tikzlibrarypaths.ortho.tex, and
  • a sample code with two TikZ pictures.

Save the .tex files as they are and place them either in your local texmf tree or in the same folder as your main .tex file.

The paths.ortho provides

  • the path operators r-ud, r-rl, r-du and r-lr, they can be used like -- or -| for example;
  • the keys udlr distance as well as for every operator one <operator> distance, which sets the distance between the middle part of the line and the nearest node; and
  • the styles ud, rl, du and lr, they can be used with the path operators to and edge and accept an optional parameter, the distance.

Furthermore, nodes/coordinates can be placed at any position. Similar to the |- and -| operators, the corner points lie at 0.25 and 0.75; this can be set to 1/<n> and (<n>-1)/<n> with udlr/spacing=<n>, i.e. using udlr/spacing=3 sets the corner at 0.3333 and 0.6667. The default is 4.

There’s also the boolean udlr/only middle which sets the corner points at 0 and 1 respectively.

More of this is explained in my answer to Vertical and horizontal lines in pgf-tikz.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning, paths.ortho}
\tikzset{
  block/.style={rectangle,draw,minimum size=1cm},
  line/.style={draw, -latex}
}
\begin{document}
\begin{tikzpicture}[node distance = 1cm]
  % Place nodes
  \node [block]             (a) {a};
  \node [block, below=of a] (b) {b};
  \node [block, right=of a] (c) {c};
  \node [block, below=of c] (d) {d};

  \path[line, very thick] (a) edge[ud] (c)
                          (c) edge[rl] (d)
                          (d) edge[du] (b)
                          (b) edge[lr] (a);

  \path[line, green, thick, udlr/distance=0.25cm] (a) edge[du] (c) 
                                                  (c) edge[lr] (d)
                                                  (d) edge[ud] (b)
                                                  (b) edge[rl] (a);

  \draw[red] (a) r-ud (c) r-rl (d) r-du (b) r-lr (a);
\end{tikzpicture}
\end{document}

Output 1

enter image description here

Examples of the usages of this library …

… can be found in paths.ortho-hvvh.tex and paths.ortho-udlr.tex. Animations created from these examples are hidden behind the following links:

  • Output (-|-/|-|)
  • Output (udlr/distance)

One way to do it is to access the east anchor points, applying an xshift and draw form there:

enter image description here

Note:

  • As per Matthew Leingang's answer, there is also the |- syntax, but I always have to either look that up or do trial and error to get it right.

Code:

\documentclass[class=article,border=2pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

% Define block styles
\tikzset{
    block/.style={rectangle, draw, line width=0.5mm, black, text width=5em, text centered,                 rounded corners, minimum height=2em},
    line/.style={draw, -latex}
}% <- if you insist in using this in the document add this % here.
\begin{document}
\begin{tikzpicture}[node distance = 1cm, auto]
    % Place nodes
    \node [block] (BLOCK1) {a};
    \node [block, below of=BLOCK1] (BLOCK2) {b};
    \node [block, below of=BLOCK2, node distance=1cm] (BLOCK3) {c};
    % Draw edges
    \path [line] (BLOCK1) -- (BLOCK2);
    \path [line] (BLOCK2) -- (BLOCK3);

\path [line, red, thick] (BLOCK3.east) --
    ([xshift=0.5cm]BLOCK3.east) --
    ([xshift=0.5cm]BLOCK1.east) --
    (BLOCK1.east);
\end{tikzpicture}
\end{document}

Tags:

Tikz Pgf