Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the tree-like graph in Latex?

Tags:

latex

diagram

I need to use LaTeX to create the following graph. I am just completely stuck with no idea how to get started. It seems there are some packages like TikZ that I could use to plot tree type of images, however I could not find anything to my example.

graph

Notice that some of those are arrows, while some are just line segments. And most examples I found are vertical structure, but this one is horizontal.

Any tips would be appreciated.

like image 704
battousai1983 Avatar asked Nov 20 '17 09:11

battousai1983


People also ask

How do you draw a tree in TIKZ?

We can easily start drawing our tree using by starting a node, with \node command. We need to provide its content in curly parentheses. To create child nodes, we can use child {} command as we continue in the node. All the nested children should go in the parentheses.


1 Answers

To provide my best suggestion I used trees library from TikZ.

The code:

\documentclass[tikz,margin=2mm]{standalone}
\usetikzlibrary{trees,arrows}
\begin{document}
\tikzstyle{level 1}=[level distance=30mm, sibling distance=30mm]
\tikzstyle{level 2}=[level distance=30mm, sibling distance=15mm]
\tikzstyle{level 3}=[level distance=20mm]
\begin{tikzpicture}[grow=right,->,>=angle 60]
%\begin{scope}[yshift=0]
  \node {$A_{1,1}$}
    child {node {$A_{2,2}$}
      child {node {$A_{3,2}$}
        child[-] {node{$S^{<4>}$}}  
      }
      child {node{$A_{3,1}$}
        child[-] {node{$S^{<3>}$}}  
      }
    }
    child {node {$A_{2,1}$}
      child {node{$A_{3,2}$}
        child[-] {node{$S^{<2>}$}}  
      }
      child {node{$A_{3,1}$}
        child[-] {node{$S^{<1>}$}}  
      }
    };
%\end{scope}
\begin{scope}[yshift=-6cm]
  \node {$A_{1,2}$}
    child {node {$A_{2,2}$}
      child {node {$A_{3,2}$}
        child[-] {node{$S^{<8>}$}}  
      }
      child {node {$A_{3,1}$}
        child[-] {node{$S^{<7>}$}}  
      }
    }
    child {node {$A_{2,1}$}
      child {node {$A_{3,2}$}
        child[-] {node{$S^{<6>}$}}
      }
      child {node {$A_{3,1}$}
        child[-] {node{$S^{<5>}$}}  
      }
    };
\end{scope}
\end{tikzpicture}
\end{document}

And the output, very similar to yours.

output image

Notice how no arrows at level 3 are provided by the syntax child[-] instead of child (default is ->,>=angle 60).

like image 142
MattAllegro Avatar answered Sep 18 '22 06:09

MattAllegro