# Tree structure in latex

I have trying to get this tree structure in latex but I don't find any example. Can someone help me?

[]

• See second example in Tikz manual (v 3.0.1a), on page 322. On pages before you can see, how to add text in nodes etc. – Zarko Oct 25 '15 at 21:26
• Welcome @ OP! @Zarko I don't think that will work here. A tree has a single root and this doesn't. It is, if I understand the terminology correctly, actually a graph. Still, TikZ is a good suggestion - but probably a different section of the manual is needed. – cfr Oct 25 '15 at 21:36
• @Zarko Actually, maybe you were thinking there's a way to fake it? – cfr Oct 25 '15 at 21:39
• @cfr, seems that you have right. I can make fake tree, however, its branches doesn't grow in desired angles ... better aproach is proba – Zarko Oct 25 '15 at 22:26
• @cfr, seems that I was to optimistic. I can fake tree to be similar to given sketch, however one branch I cannot convince to grow in desired angle, Probably it will be easy to use graph or draw directly in tikz. Sorry for noise ... – Zarko Oct 25 '15 at 22:29

Draw directly with TikZ and use of tikzlibrary positioning:

    \documentclass[border=3mm, tikz ]{standalone}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
\coordinate (a);
\coordinate[right=33mm of a]    (b);
\coordinate[above right=11mm and 22mm of b]    (c);
\draw (a) -- node[above] {2} + (150:22mm) node[left] {2};
\draw (a) -- node[below] {2} + (210:22mm) node[left] {4};
%
\draw (a) -- node[above] {1} (b)
-- node[above] {0.5} (c)
-- node[above] {1} + (30:12mm) node[right] {3};
\draw (c) -- node[below] {4} + (12mm,0) node[right] {5};
\draw (b) -- node[below] {1} + (330:22mm) node[right] {1};
\end{tikzpicture}
\end{document}


Here's a version using the graphs and graphdrawing libraries. It needs to be compiled with LuaLaTeX.

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{graphs,quotes,graphdrawing}
\usegdlibrary{layered}
\begin{document}
\begin{tikzpicture}[every edge quotes/.append style={midway, auto, font=\scriptsize, inner sep=1.5pt}]
\graph [layered layout, horizontal=a to b] {
{2 [<"2"], 4[<"2"']} -- a/""  -- ["1"] b/"" -- {c/"" [>"0.5"] -- {3 [>"1"], 5 [>"4"']}, 1 [>"1"']}
};
\draw (2) -- (a.center) -- (4) (a.center) -- (b.center) -- (c.center) (b.center) -- (1) (c.center) -- (3) (c.center) -- (5);
\end{tikzpicture}
\end{document}


The final \draw command is needed only because I cannot figure out how to incorporate empty nodes into the graph correctly. Hopefully somebody will comment and give me a pointer to the relevant bit of the manual! (The answer may be that I should really be specifying the graph itself differently - I'm not sure.)

Here is a short code with pst-tree:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}%
\usepackage{lmodern}
\usepackage{ pst-tree}
\usepackage{auto-pst-pdf}
\pagestyle{empty}

\begin{document}

\psset{treesep=1.8cm, nodesepB=4pt, levelsep=1.8cm, tpos=0.4}
$\begin{psmatrix}[shortput=nab, colsep=3cm] \pstree[treemode=L] {\Tp{\pnode{R1}}}{{\psset{tpos=0.5}\Tr{2}_{\scriptstyle2}}\Tr{4}_{\scriptstyle2}} & \pstree[treemode=R, nodesepB=0pt] % {\Tp{\pnode{R2}}}{\pstree[treesep=1.8cm, nodesepB=4pt]{\Tp^{\scriptstyle0.5}} {\Tr{3}^{\scriptstyle1}\Tr{5}_{\scriptstyle4}}% \Tr{\ 1}_{\scriptstyle1}} \ncline[nodesepB=0pt]{R1}{R2}\naput{\scriptstyle1} \end{psmatrix}$

\end{document}