3

I am trying to place two nodes in the northeast and and northwest of another node. However, I am facing a visual issue.

Here is the example that I am working on.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}


\tikzstyle{block} = [rectangle, draw, fill=white!20,  node distance=3cm,
    text width=6em, text centered, rounded corners, minimum height=3em]
\tikzstyle{line} = [draw, very thick, color=black!50, -latex']


\begin{tikzpicture}[scale=2,node distance = 2cm, auto]
    \node [block] (A) {Initial step};
    \node [block, right =of A] (B) {The next step};

    \begin{scope}[node distance=4cm and 5cm]
        \node [block, right = of B, anchor = south east] (C) {The third step};
        \node [block, right = of B, , anchor = north east ] (D) {The fourth step};
    \end{scope}

    \path [line] (A) -- (B);
    \path [line] (B) -- (C);
    \path [line] (B) -- (D);
\end{tikzpicture}
\end{document}

enter image description here

The first issue is that as you can see I have different horizontal distances between nodes. The second problem is that I am not able to add vertical distance between nodes as shown in the image.

2

As suplement to @farahfeza answer:

  • I would define node distance only once:
    • uniform distance in diagram,
    • shorter code
  • Use of tikzstyle is deprecated, instead it you should use \tikset or define styles in `tikzpicture options (as is done in MWE below)
  • Also library arrows is deprecated. Instead it is better to use more powerful arrows.meta
\documentclass[margin=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                shapes}
                
\begin{document}
    \begin{tikzpicture}[
 node distance = 5mm and 22mm, 
  block/.style = {draw, rounded corners, fill=#1,
                  minimum height=3em, text width=6em, align=center},
block/.default = white,
every edge/.append style = {draw=black!50, thick, -Latex}
                    ]
\node [block] (A) {Initial step};
\node [block, right =of A] (B) {The next step};
\node [block, above right = of B] (C) {The third step};
\node [block, below right = of B] (D) {The fourth step};
%
\path   (A) edge (B)
        (B.+5) edge (C.west) 
        (B.-5) edge (D.west);
    \end{tikzpicture}
\end{document}

enter image description here

2
  • request explain (B.+5) edge (C.west) (B.-5) edge (D.west); – js bibra Jan 5 at 0:18
  • 2
    @jsbibra, (B+5) is the same as (B.5) define anchor on shape borders which lie on intersection of line rotated for 5 degrees from shape center and shape border. The same is valid for B.-5 which is equal to B.355, where angle of rotation is -5 degree (= 355 degree). Is your comment about this? BTE, edge can connect only two coordinates, style connection lines can be determined by tikzset or by option to tikzpicture as is done in answer. – Zarko Jan 5 at 0:34
2

You can specify the relative x and y positions separately using the tikz library positioning, like this.

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}

\tikzstyle{block} = [rectangle, draw, fill=white!20,  node distance=3cm,
    text width=6em, text centered, rounded corners, minimum height=3em]
\tikzstyle{line} = [draw, very thick, color=black!50, -latex']


\begin{tikzpicture}[scale=2,node distance = 2cm, auto]
    \node [block] (A) {Initial step};
    \node [block, right =of A] (B) {The next step};

    \begin{scope}[node distance=4cm and 5cm]
        \node [block, above right= 1cm and 4cm of B, anchor = south east] (C) {The third step};
        \node [block, below right= 1cm and 4cm of B,  anchor = north east] (D) {The fourth step};
    \end{scope}

    \path [line] (A) -- (B);
    \path [line] (B.10) -- (C.180);
    \path [line] (B.-10) -- (D.180);
\end{tikzpicture}
\end{document}

enter image description here

2
  • Is it not sufficient to define node distance only ones (out of style definitions, out of scope)? – Zarko Jan 4 at 20:18
  • @Zarko, I produced a solution based on the OP's code. You may add a supplement to my answer. – user31034 Jan 4 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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