Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Say I have a code to draw a flow chart, I want now a arrow from node 3 to node 1, how can I do that?

1<--|
|   |
2   |
|   |
3----

MWE

\documentclass[class=article,border=0pt]{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);
\end{tikzpicture}
\end{document}
share|improve this question
    
You could also use Jake's solution to tex.stackexchange.com/questions/55068/… –  Torbjørn T. Mar 14 '13 at 7:40
add comment

3 Answers

up vote 14 down vote accepted

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

share|improve this answer
    
Someday I'll have to figure out a way to remember this syntax -- not sure why I always have to do trial and error to get it right. :-) –  Peter Grill Mar 14 '13 at 2:02
    
Me too, I am kind of confused about this syntax, tried many times and cant get it right, haha. Thank you Matthew –  Daniel Mar 14 '13 at 2:19
2  
-- ++(2cm,0cm) seems easier to understand than --++ (2cm,0cm). –  Paul Gaborit Mar 14 '13 at 7:29
1  
Ther ei sno accountin gfo rtaste, I guess. :-) –  Matthew Leingang Mar 14 '13 at 17:29
1  
@Nicolás: I would agree it's easier to read than mine, but remembering just comes with a few repetitions. I try to follow DRY when coding TikZ, so if I want to change the name of BLOCK3 I only have to change it in one place. But there is room for both methods, to be sure. –  Matthew Leingang Mar 18 at 16:35
show 3 more comments

The following answer consists of

  • the qrr-tikz-udlr.sty package file, and
  • a sample code with two TikZ pictures.

Save the qrr-tikz-udlr.sty file as it is and place it either in your local texmf tree or in the same folder as your main .tex file.

The “package” provides

  • the path operators ud, rl, du and 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 operatorstoandedge` 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.

If the node is specified before the target coordinate, it is assigned the position 0.5 (midway) as usual.

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

Further Improvements

  • Adding redundant styles to set the udlr distance like dulr distance or rldu distance.
  • Adding styles that set the distance for the four path operators independent from each other (e.g. ud distance, lr distance, etc.).
  • Adding path operators/styles that behave like -|- or |-| (see for examples [1], [2], [3], …).
  • Different timing styles, i.e. the corner points don’t lie at 0.25 and 0.75 but at, say, 1/3 and 2/3; or that only the middle part can be “nodified”, i.e the corner points lie at 0 and 1.

This breaks when …

  • … I messed up patching one of the dispatcher,
  • … another packages interferes with the dispatcher
  • … PGF/TikZ gets updated
  • … (insert your own)

qrr-tikz-udlr.sty

\RequirePackage{etoolbox}
\patchcmd{\tikz@handle@more}{\tikz@expand}{\qrr@tikz@handle@more}{}{%
    \PackageError{qrr-tikz-udlr}{Patching of \string\tikz@handle@more\space failed (I)}{}}
\patchcmd{\tikz@handle@more}{\tikz@decoration}{\tikz@d@char}{}{%
    \PackageError{qrr-tikz-udlr}{Patching of \string\tikz@handle@more\space failed (II)}{}}
\patchcmd{\tikz@l@char}{\tikz@expand}{\pgfutil@ifnextchar r{\qrr@tikz@lr@lineto}{\tikz@expand}}{}{%
    \PackageError{qrr-tikz-udlr}{Patching of \string\tikz@l@char\space failed}{}}
\patchcmd{\tikz@handle}{\tikz@rect}{\tikz@r@char}{}{%
    \PackageError{qrr-tikz-udlr}{Patching of \string\tikz@handle\space failed}{}}

\newlength\qrr@tikz@ud@distance\newlength\qrr@tikz@du@distance
\newlength\qrr@tikz@lr@distance\newlength\qrr@tikz@rl@distance
\newif\ifqrr@tikz@udlr@onlymiddle
\tikzset{
  udlr/only middle/.is if=qrr@tikz@udlr@onlymiddle,
  udlr/spacing/.code=%
    \qrr@tikz@udlr@onlymiddlefalse
    \def\qrr@tikz@udlr@timing@parts{#1}
    \pgfmathreciprocal{#1}\let\qrr@tikz@udlr@timing@first\pgfmathresult
    \pgfmathsetmacro\qrr@tikz@udlr@timing@last{1-\pgfmathresult}%
    \pgfmathreciprocal{#1-2}%
    \let\qrr@tikz@udlr@timing@subtr\pgfmathresult
    \pgfmathsetmacro\qrr@tikz@udlr@timing@factor{1+2*\pgfmathresult},
  udlr/spacing=4,
  udlr distance/.style={ud distance=#1,du distance=#1,lr distance=#1,rl distance=#1},
  ud distance/.code=\pgfmathsetlength\qrr@tikz@ud@distance{#1},
  du distance/.code=\pgfmathsetlength\qrr@tikz@du@distance{#1},
  lr distance/.code=\pgfmathsetlength\qrr@tikz@lr@distance{#1},
  rl distance/.code=\pgfmathsetlength\qrr@tikz@rl@distance{#1},
  udlr distance=.5cm,
  @udlr/.style 2 args={% #1 = distance, #2 = lineto
    to path={
      \pgfextra
          \if\relax\detokenize{#1}\relax\else\expandafter\pgfmathsetlength\csname qrr@tikz@#2@distance\endcsname{#1}\fi
      \endpgfextra
       #2 (\tikztotarget) \tikztonodes}},
  ud/.style={@udlr={#1}{ud}},du/.style={@udlr={#1}{du}},rl/.style={@udlr={#1}{rl}},lr/.style={@udlr={#1}{lr}},
  ud/.default=,du/.default=,rl/.default=,lr/.default=}
\def\tikz@d@char{\pgfutil@ifnextchar e\tikz@decoration\qrr@tikz@du@lineto}
\def\tikz@r@char{\pgfutil@ifnextchar e\tikz@rect\qrr@tikz@rl@lineto}
\def\qrr@tikz@handle@more{%
  \ifx\@let@token u%
    \let\@next\qrr@tikz@ud@lineto
  \else
    \let\@next\tikz@expand
  \fi\@next}

% ud style
\def\qrr@tikz@ud@lineto d{\qrr@tikz@ud@lineto@next}
\def\qrr@tikz@ud@lineto@next{%
  \pgfutil@ifnextchar n
  {\tikz@collect@label@onpath\qrr@tikz@ud@lineto@next}
  {\pgfutil@ifnextchar c{\tikz@collect@coordinate@onpath\qrr@tikz@ud@lineto@next}%
    {\tikz@scan@one@point\qrr@tikz@@ud@lineto}}}
\def\qrr@tikz@@ud@lineto#1{%
  \edef\tikz@timer@start{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \advance\tikz@lasty1pt%
  \tikz@flush@moveto@toward{\pgfqpoint{\tikz@lastx}{\tikz@lasty}}\pgf@xc\pgf@yc
  \tikz@make@last@position{#1}%
  \iftikz@shapeborder
    {%
      \pgf@process{\pgfpointshapeborder{\tikz@shapeborder@name}{\pgfqpoint{\tikz@lastx}{\pgf@yc}}}%
      \ifdim\pgf@yc<\pgf@y\pgf@yc=\pgf@y\fi
      \advance\pgf@yc\qrr@tikz@ud@distance
      \tikz@make@last@position{\pgfqpoint{\pgf@x}{\pgf@y}}%
      \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
      \tikz@path@lineto{\pgfqpoint{\tikz@lastx}{\pgf@yc}}%
      \tikz@path@lineto{\tikz@last@position}%
      \pgf@xc.5\pgf@xc\advance\pgf@xc.5\tikz@lastx
      \xdef\tikz@timer@middle@temp{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
      \xdef\tikz@timer@end@temp{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}% move out of group
    }%
    \let\tikz@timer@middle=\tikz@timer@middle@temp
    \let\tikz@timer@end=\tikz@timer@end@temp%
    \edef\tikz@moveto@waiting{\tikz@shapeborder@name}% 
  \else
    \ifdim\pgf@yc<\tikz@lasty\pgf@yc\tikz@lasty\fi
    \advance\pgf@yc\qrr@tikz@ud@distance
    \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
    \tikz@path@lineto{\pgfqpoint{\tikz@lastx}{\pgf@yc}}%
    \tikz@path@lineto{\tikz@last@position}%
    \pgf@xc.5\pgf@xc\advance\pgf@xc.5\tikz@lastx
    \edef\tikz@timer@middle{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
    \edef\tikz@timer@end{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \fi
  \let\tikz@timer\tikz@timer@udline\tikz@scan@next@command}

% du style
\def\qrr@tikz@du@lineto u{\qrr@tikz@du@lineto@next}
\def\qrr@tikz@du@lineto@next{%
  \pgfutil@ifnextchar n
  {\tikz@collect@label@onpath\qrr@tikz@du@lineto@next}
  {\pgfutil@ifnextchar c{\tikz@collect@coordinate@onpath\qrr@tikz@du@lineto@next}%
    {\tikz@scan@one@point\qrr@tikz@@du@lineto}}}
\def\qrr@tikz@@du@lineto#1{%
  \edef\tikz@timer@start{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \advance\tikz@lasty-1pt%
  \tikz@flush@moveto@toward{\pgfqpoint{\tikz@lastx}{\tikz@lasty}}\pgf@xc\pgf@yc
  \tikz@make@last@position{#1}%
  \iftikz@shapeborder
    {%
      \pgf@process{\pgfpointshapeborder{\tikz@shapeborder@name}{\pgfqpoint{\tikz@lastx}{\pgf@yc}}}%
      \ifdim\pgf@yc>\pgf@y\pgf@yc\pgf@y\fi
      \advance\pgf@yc-\qrr@tikz@du@distance
      \tikz@make@last@position{\pgfqpoint{\pgf@x}{\pgf@y}}%
      \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
      \tikz@path@lineto{\pgfqpoint{\tikz@lastx}{\pgf@yc}}%
      \tikz@path@lineto{\tikz@last@position}%
      \pgf@xc.5\pgf@xc\advance\pgf@xc.5\tikz@lastx
      \xdef\tikz@timer@middle@temp{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
      \xdef\tikz@timer@end@temp{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}% move out of group
    }%
    \let\tikz@timer@middle\tikz@timer@middle@temp
    \let\tikz@timer@end\tikz@timer@end@temp%
    \edef\tikz@moveto@waiting{\tikz@shapeborder@name}% 
  \else
    \ifdim\pgf@yc>\tikz@lasty\pgf@yc\tikz@lasty\fi
    \advance\pgf@yc-\qrr@tikz@du@distance
    \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
    \tikz@path@lineto{\pgfqpoint{\tikz@lastx}{\pgf@yc}}%
    \tikz@path@lineto{\tikz@last@position}%
    \pgf@xc.5\pgf@xc\advance\pgf@xc.5\tikz@lastx
    \edef\tikz@timer@middle{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
    \edef\tikz@timer@end{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \fi
  \let\tikz@timer\tikz@timer@duline\tikz@scan@next@command}

% lr style
\def\qrr@tikz@lr@lineto r{\qrr@tikz@lr@lineto@next}
\def\qrr@tikz@lr@lineto@next{%
  \pgfutil@ifnextchar n
  {\tikz@collect@label@onpath\qrr@tikz@lr@lineto@next}
  {\pgfutil@ifnextchar c{\tikz@collect@coordinate@onpath\qrr@tikz@lr@lineto@next}%
    {\tikz@scan@one@point\qrr@tikz@@lr@lineto}}}
\def\qrr@tikz@@lr@lineto#1{%
  \edef\tikz@timer@start{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \advance\tikz@lastx-1pt%
  \tikz@flush@moveto@toward{\pgfqpoint{\tikz@lastx}{\tikz@lasty}}\pgf@xc\pgf@yc
  \tikz@make@last@position{#1}%
  \iftikz@shapeborder
    {%
      \pgf@process{\pgfpointshapeborder{\tikz@shapeborder@name}{\pgfqpoint{\pgf@xc}{\tikz@lasty}}}%
      \ifdim\pgf@xc>\pgf@x\pgf@xc\pgf@x\fi
      \advance\pgf@xc-\qrr@tikz@lr@distance
      \tikz@make@last@position{\pgfqpoint{\pgf@x}{\pgf@y}}%
      \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
      \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\tikz@lasty}}%
      \tikz@path@lineto{\tikz@last@position}%
      \pgf@yc.5\pgf@yc\advance\pgf@yc.5\tikz@lasty
      \xdef\tikz@timer@middle@temp{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
      \xdef\tikz@timer@end@temp{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}% move out of group
    }%
    \let\tikz@timer@middle\tikz@timer@middle@temp
    \let\tikz@timer@end\tikz@timer@end@temp%
    \edef\tikz@moveto@waiting{\tikz@shapeborder@name}% 
  \else
    \ifdim\pgf@xc>\tikz@lastx\pgf@xc\tikz@lastx\fi
    \advance\pgf@xc-\qrr@tikz@lr@distance
    \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
    \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\tikz@lasty}}%
    \tikz@path@lineto{\tikz@last@position}%
    \pgf@yc.5\pgf@yc\advance\pgf@yc.5\tikz@lasty
    \edef\tikz@timer@middle{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
    \edef\tikz@timer@end{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \fi
  \let\tikz@timer\tikz@timer@lrline
  \tikz@scan@next@command
}

% rl style
\def\qrr@tikz@rl@lineto l{\qrr@tikz@rl@lineto@next}
\def\qrr@tikz@rl@lineto@next{%
  \pgfutil@ifnextchar n
  {\tikz@collect@label@onpath\qrr@tikz@rl@lineto@next}
  {\pgfutil@ifnextchar c{\tikz@collect@coordinate@onpath\qrr@tikz@rl@lineto@next}%
    {\tikz@scan@one@point\qrr@tikz@@rl@lineto}}}
\def\qrr@tikz@@rl@lineto#1{%
  \edef\tikz@timer@start{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \advance\tikz@lastx1pt%
  \tikz@flush@moveto@toward{\pgfqpoint{\tikz@lastx}{\tikz@lasty}}\pgf@xc\pgf@yc
  \tikz@make@last@position{#1}%
  \iftikz@shapeborder
    {%
      \pgf@process{\pgfpointshapeborder{\tikz@shapeborder@name}{\pgfqpoint{\pgf@xc}{\tikz@lasty}}}%
      \ifdim\pgf@xc<\pgf@x\pgf@xc\pgf@x\fi
      \advance\pgf@xc\qrr@tikz@rl@distance
      \tikz@make@last@position{\pgfqpoint{\pgf@x}{\pgf@y}}%
      \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
      \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\tikz@lasty}}%
      \tikz@path@lineto{\tikz@last@position}%
      \pgf@yc.5\pgf@yc\advance\pgf@yc.5\tikz@lasty
      \xdef\tikz@timer@middle@temp{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
      \xdef\tikz@timer@end@temp{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}% move out of group
    }%
    \let\tikz@timer@middle\tikz@timer@middle@temp
    \let\tikz@timer@end\tikz@timer@end@temp
    \edef\tikz@moveto@waiting{\tikz@shapeborder@name}% 
  \else
    \ifdim\pgf@xc<\tikz@lastx\pgf@xc\tikz@lastx\fi
    \advance\pgf@xc\qrr@tikz@rl@distance
    \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}%
    \tikz@path@lineto{\pgfqpoint{\pgf@xc}{\tikz@lasty}}%
    \tikz@path@lineto{\tikz@last@position}%
    \pgf@yc.5\pgf@yc\advance\pgf@yc.5\tikz@lasty
    \edef\tikz@timer@middle{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@yc}}%
    \edef\tikz@timer@end{\noexpand\pgfqpoint{\the\tikz@lastx}{\the\tikz@lasty}}%
  \fi
  \let\tikz@timer\tikz@timer@rlline%
  \tikz@scan@next@command%
}

\def\tikz@timer@rlline{%
  \pgf@process{\tikz@timer@start}\pgf@ya\pgf@y
  \pgf@process{\tikz@timer@end}\pgf@yc\pgf@y
  \pgf@process{\tikz@timer@middle}\pgf@xb\tikz@time pt%
  \ifqrr@tikz@udlr@onlymiddle
    \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}%
      {\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@ya}}{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@yc}}}%
  \else
    \ifdim\tikz@time pt<\qrr@tikz@udlr@timing@first pt% first quarter
      \pgf@xb\qrr@tikz@udlr@timing@parts\pgf@xb
      \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}{\noexpand\tikz@timer@start}{%
          \noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@ya}}}%
    \else
      \ifdim\tikz@time pt>\qrr@tikz@udlr@timing@last pt% last quarter
        \pgf@xb\qrr@tikz@udlr@timing@parts\pgf@xb
        \advance\pgf@xb\dimexpr-\qrr@tikz@udlr@timing@parts pt+1pt\relax%
        \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}%
          {\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@yc}}{\noexpand\tikz@timer@end}}%
      \else% middle half
        \pgf@xb\qrr@tikz@udlr@timing@factor\pgf@xb%
        \advance\pgf@xb-\qrr@tikz@udlr@timing@subtr pt%
        \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}%
          {\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@ya}}{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@yc}}}%
      \fi\fi\fi\tikz@marshal}
\def\tikz@timer@udline{%
  \pgf@process{\tikz@timer@start}%
  \pgf@xa\pgf@x
  \pgf@process{\tikz@timer@end}%
  \pgf@xc\pgf@x
  \pgf@process{\tikz@timer@middle}%
  \pgf@xb\tikz@time pt%
\ifqrr@tikz@udlr@onlymiddle
  \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}%
    {\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@y}}{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@y}}}%
\else
  \ifdim\tikz@time pt<\qrr@tikz@udlr@timing@first pt% first quarter
    \pgf@xb=\qrr@tikz@udlr@timing@parts\pgf@xb
    \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}{\noexpand\tikz@timer@start}{%
        \noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@y}}}%
  \else
    \ifdim\tikz@time pt>\qrr@tikz@udlr@timing@last pt% last quarter
      \pgf@xb=\qrr@tikz@udlr@timing@parts\pgf@xb
      \advance\pgf@xb by\dimexpr-\qrr@tikz@udlr@timing@parts pt+1pt\relax%
      \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}%
        {\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@y}}{\noexpand\tikz@timer@end}}%
    \else% middle half
      \pgf@xb=\qrr@tikz@udlr@timing@factor\pgf@xb%
      \advance\pgf@xb by-\qrr@tikz@udlr@timing@subtr pt%
      \edef\tikz@marshal{\noexpand\pgftransformlineattime{\pgf@sys@tonumber{\pgf@xb}}%
        {\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@y}}{\noexpand\pgfqpoint{\the\pgf@xc}{\the\pgf@y}}}%
      \fi\fi\fi\tikz@marshal}

\let\tikz@timer@lrline\tikz@timer@rlline
\let\tikz@timer@duline\tikz@timer@udline

Code

\documentclass[tikz,border=5pt]{standalone}

\usepackage{tikz,qrr-tikz-udlr}
\usetikzlibrary{positioning}

\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) ud (c) rl (d) du (b) lr (a);
\end{tikzpicture}

\tikzset{nodes={font=\tiny},udlr distance=2cm,auto}
\begin{tikzpicture}
  \def\mylist{0,.1,.2,.25,.3,.5,.7,.75,.8,.9,1.0}
  \draw (0,0) rl (0,-2) \foreach \pos in \mylist {node[pos=\pos] {\pos}};

  \draw[yshift=-3cm] (0,0) rl (1,-2) \foreach \pos in \mylist {node[pos=\pos] {\pos}};

\end{tikzpicture}

\begin{tikzpicture}[udlr/spacing=3]
  \def\mylist{0,.1667,.3,.3334,.5,.6666,.7,.8333,1.0}
  \draw (0,0) rl (0,-2) \foreach \pos in \mylist {node[pos=\pos] {\pos}};

  \draw[yshift=-3cm] (0,0) rl (1,-2) \foreach \pos in \mylist {node[pos=\pos] {\pos}};

\end{tikzpicture}

\begin{tikzpicture}[udlr/only middle,udlr distance=.1cm]
  \def\mylist{0,0.2,0.3333,0.5,0.6667,0.8,1}
  \draw (0,0) rl (0,-2) \foreach \pos in \mylist {node[pos=\pos] {\pos}};

  \draw[yshift=-3cm] (0,0) rl (1,-2) \foreach \pos in \mylist {node[pos=\pos] {\pos}};
\end{tikzpicture}
\end{document}

Output 1

enter image description here

Output 2 (n = 4)

enter image description here

Output 3 (n = 3)

enter image description here

Output 4 (only middle)

enter image description here

share|improve this answer
1  
For an up-to-date library for “udlr”, |-| and -|- paths, see my answer to Vertical and horizontal lines in pgf-tikz. –  Qrrbrbirlbel Apr 23 '13 at 2:16
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.