2

I am aiming to make a flow diagram as drawn herehowever I have not been able to add the four boxes and include the top box centered. Also note the top box should be a full box. Please assist if you could!

I try to add this but does not come out right. Here is the code:

     [,name=Parent
   [,name=Parent1
    [,no edge,name=Child1
      [,no edge,name=GrandChild1]
    ]  
    [,no edge,name=Child2
      [,no edge,name=GrandChild2]
    ]  
    [,no edge,name=Child3
      [,no edge,name=GrandChild3]
    ]  
    [,no edge,name=Child4
      [,no edge,name=GrandChild4]
    ]  
  ] ]
**\draw[->] (Parent.west) -| (Parent1.north);**  
Oscar
  • 123

1 Answers1

2

Here is one possibility: let forest place the boxes, suppress the edges and draw them afterwards.

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc}
\usepackage{forest}
\begin{document}
\tikzset{>=latex}
\begin{forest}
for tree={inner sep=2pt,outer
sep=0pt,align=center,font=\sffamily\footnotesize,draw,minimum width=3cm,
minimum height=0.5cm},
  [,name=Parent
    [,no edge,name=Child1
      [,no edge,name=GrandChild1]
    ]  
    [,no edge,name=Child2
      [,no edge,name=GrandChild2]
    ]  
    [,no edge,name=Child3
      [,no edge,name=GrandChild3]
    ]  
    [,no edge,name=Child4
      [,no edge,name=GrandChild4]
    ]  
  ]
\draw[->] (Parent.west) -| (Child1.north);  
\coordinate (x2) at ($(Child2.north)!0.5!(Child2.north east)$);
\draw[->] (Parent.south -| x2) -- (x2);  
\coordinate (x3) at ($(Child3.north)!0.5!(Child3.north west)$);
\draw[->] (Parent.south -| x3) -- (x3);  
\draw[->] (Parent.east) -| (Child4.north);  
\foreach \X in {1,...,4}
{\draw[->] (Child\X) -- (GrandChild\X);}
\end{forest}
\end{document}

enter image description here

Notice that you could also do the whole thing in forest, see e.g. here, but I would like to argue that this is more effort.

  • This is really good thanks so much. Now what if I wanted to use the tikz environment because I already have a chart being designed in it. Say I have a box called A. How could I link the four boxes as shown in the original post (box2). – Oscar Apr 17 '18 at 00:40
  • @Oscar First of all, forest is based on TikZ, and my example shows how you can give the boxes names such that they can be used as TikZ nodes (what they really are). Second, if you already have a TikZ code that you're working with, why don't you post it in your question? –  Apr 17 '18 at 00:43
  • @Oscar And everything starting from \draw[->] (Parent.west) -| (Child1.north); will work in your TikZ picture, you only need to adjust the node names. –  Apr 17 '18 at 01:06
  • Your code is much helpful but the text I wish to enter does not fit in the boxes and I am not able to fix this. I added a new image that I would hope to integrate into your code but again have much issue. You will see the new code in there as well. – Oscar Apr 17 '18 at 10:55