I'm trying to draw a tree using Tikz
. My code is as follows:
\begin{figure}
\centering
\begin{tikzpicture}[node distance=1.5cm]
\tikzstyle{process} = [rectangle, minimum width=0.7cm, minimum height=0.7cm,text centered, draw=black, fill=white!100]
\tikzstyle{arrow} = [thick,->,>=stealth]
\node (proA) [process] {{A}};
\node (proB) [process, right of = proA] {{B}};
\node (pro1) [process, below of = proA] {{1}};
\node (pro2) [process, below of = pro1] {{$S_2$}};
\node (pro3) [process, right of = pro2] {{$S_3$}};
\node (pro6) [process, below of = pro2] {{6}};
\node (pro7) [process, right of = pro6] {{7}};
\node (pro8) [process, right of = pro7] {{8}};
\node (pro9) [process, right of = pro8] {{9}};
\draw [arrow] (pro1) -- (pro2);
\draw [arrow] (pro1) -- (pro3);
\draw [arrow] (pro2) -- (pro6);
\draw [arrow] (pro2) -- (pro7);
\draw [arrow] (pro3) -- (pro8);
\draw [arrow] (pro3) -- (pro9);
\draw [arrow] (proA) -- (pro1);
\draw [arrow] (proB) -- (pro1);
\end{tikzpicture}
\label{fig:CTU_partitioning}
\end{figure}
However, it produces output similar to the right side of the image, when I require output similar to the left side.
How can I fix this out? There could be more levels and nodes in the tree. please suggest a smart way to draw this type of figure in latex.
Best Answer
By use of
forest
package (for tree below node1
) and TikZ picture for node above (for start, however there is more sophisticated way to draw complete images with forest):