3

I have the following MNWE:

\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{process} = [rectangle, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}

\begin{tikzpicture}[node distance=1cm]

\node (start) [process] {1};
\node (node2r) [process, below right=of start] {2r};
\node (node3r) [process, below=of node2r] {3r};
\node (node4r) [process, below=of node3r] {4r};
\node (node2l) [process, below left=of start] {2l};
\node (node4l) [process, below=of node2l, left=of node4r] {4l};
\node (end) [process, below left=of node4r] {4};

\draw [arrow] (start) -| (node2r);
\draw [arrow] (start) -| (node2l);
\draw [arrow] (node2l) -- (node4l);
\draw [arrow] (node2r) -- (node3r);
\draw [arrow] (node3r) -- (node4r);
\draw [arrow] (node4r) |- (end);
\draw [arrow] (node4l) |- (end);

\end{tikzpicture}

\end{document}

This generates the following output.

Unintended alignment of 4l

How do I adjust the code so that 4l aligns with both 2l (horizontally) and 4r (vertically)?


Bonus question: How do I ensure that 1 and 5 aligns vertically? (Occurs if the rectangles differ in width)

5
  • 1 and 5 cannot align horizontally since it's one on top of the other, unless you mean vertically?
    – Alenanno
    Aug 16, 2016 at 11:18
  • Damnit, corrected.
    – T'n'E
    Aug 16, 2016 at 11:27
  • @Alenanno I understand horizontal alignment as aligning things along the horizontal axis (e.g. have same x-position, different y), so you can align 1 and 5 horizontally. Aug 16, 2016 at 11:28
  • @TorbjørnT. Well, I consider horizontally aligned to mean "next to each other, but on the same y", while vertical aligned to mean "on top of each other, but same x". See also this image.
    – Alenanno
    Aug 16, 2016 at 11:31
  • @Alenanno Not in my vocabulary, and the tag wikis agree with me. But this is off topic here, continue in chat if necessary. Aug 16, 2016 at 11:34

1 Answer 1

4

You can use the syntax at (coordinate|-coordinate) for example. By the way, I switched to \tikzset because \tikzstyle is deprecated (even though it may be still supported).

Output

enter image description here

Code

\documentclass[tikz, margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc, shapes.geometric, arrows}

\tikzset{
    process/.style={rectangle, minimum height=1cm, text centered, draw=black, fill=orange!30},
    arrow/.style={thick,->,>=stealth},
}

\begin{document}
\begin{tikzpicture}[node distance=1cm]

\node (start) [process] {1};
\node (node2r) [process, below right=of start] {2r};
\node (node3r) [process, below=of node2r] {3r};
\node (node4r) [process, below=of node3r] {4r};
\node (node2l) [process, below left=of start] {2l};
\node (node4l) [process, ] at (node2l|-node4r) {4l};
\node (end) [process] at ($(node4l)!.5!(node4r)+(0,-2cm)$) {5moretext};

\draw [arrow] (start) -| (node2r);
\draw [arrow] (start) -| (node2l);
\draw [arrow] (node2l) -- (node4l);
\draw [arrow] (node2r) -- (node3r);
\draw [arrow] (node3r) -- (node4r);
\draw [arrow] (node4r) |- (end);
\draw [arrow] (node4l) |- (end);

\end{tikzpicture}
\end{document}
4
  • Very neat. Any input for the bonus question?
    – T'n'E
    Aug 16, 2016 at 11:36
  • @T'n'E See edit.
    – Alenanno
    Aug 16, 2016 at 11:39
  • "is not deprecated", isn't it exactly deprecated?
    – daleif
    Aug 16, 2016 at 11:40
  • 1
    @daleif Ops. :D
    – Alenanno
    Aug 16, 2016 at 11:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .