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

[enter image description here]

  • 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
  • 2
    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}

\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};

enter image description here

| improve this answer | |

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

hacked graph

\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);

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.)

| improve this answer | |

Here is a short code with pst-tree:

\usepackage{ pst-tree}


\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}}
    \end{psmatrix} \]


enter image description here

| improve this answer | |

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.