4

How to draw a tree like

enter image description here

using LaTeX and how can I give the labelling to the vertices and the edges?

doncherry
  • 54,637
  • 1
    related: http://meta.tex.stackexchange.com/questions/1538/policy-on-how-do-i-draw-this-questions – masu Dec 09 '13 at 15:43
  • 4
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – texenthusiast Dec 09 '13 at 15:49
  • I don't suppose one of these answers would help? http://tex.stackexchange.com/questions/39149/how-can-we-draw-a-christmas-tree-with-decorations-using-tikz – David Carlisle Dec 09 '13 at 15:49
  • 3
    -1: “This question does not show any research effort” – doncherry Dec 09 '13 at 16:04
  • @Senthil.G: At least make an effort to give the question a meaningful title so people with a similar problem have a chance of finding this question. – Jake Dec 09 '13 at 21:46

2 Answers2

8

With TikZ, for the fun of doing it in one path (just a start):

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees}
\tikzset{level 1/.style={
  level distance=2cm, sibling distance=1cm
  },
  point/.style={circle,
    fill,
    inner sep=1.4pt
  },
  every label/.style={font=\scriptsize}
}

\begin{document}
\begin{tikzpicture}[]
\draw (0,0)
 node[point,label={north:0}]{}
  child{edge from parent node[label={west:15}]{}; \node[point,label={south:30}]{}}
  child{edge from parent node[label={west:21}]{}; \node[point,label={south:42}]{}}
  child{edge from parent node[label={east:28}]{}; \node[point,label={south:56}]{}}
  child{edge from parent node[label={east:36}]{}; \node[point,label={south:72}]{}}
--node[above,midway,label={above:1}]{}(3,0)
node[point,label={south:2}] {}[grow'=up]
  child{edge from parent node[label={west:45}]{}; \node[point,label={north:88}]{}}
  child{edge from parent node[label={west:55}]{}; \node[point,label={north:108}]{}}
  child{edge from parent node[label={east:66}]{}; \node[point,label={north:130}]{}}
  child{edge from parent node[label={east:78}]{}; \node[point,label={north:154}]{}}
--node[above,midway,label={above:3}]{}(6,0)
node[point,label={north:4}] {} [grow'=down]
  child{edge from parent node[label={west:..}]{}; \node[point,label={south:..}]{}}
  child{edge from parent node[label={west:..}]{}; \node[point,label={south:..}]{}}
  child{edge from parent node[label={east:..}]{}; \node[point,label={south:..}]{}}
  child{edge from parent node[label={east:..}]{}; \node[point,label={south:..}]{}}  
  ; 
\end{tikzpicture}
\end{document}

The result:

enter image description here

6
\documentclass[pstricks]{standalone}
\usepackage{pst-tree}
\begin{document}

\small\psset{radius=3pt,treesep=6mm}
\begin{pspicture}(-2,-2.75)(13,3)
\psline(12,0)
\psforeach{\iA}{0,1,3,4,5,6,7,9,10,11,12}{\uput[90](\iA,0){\iA}}
\psforeach{\iA}{2,8}{\uput[-90](\iA,0){\iA}}
\rput[t](0,3pt){%
  \pstree[radius=3pt,tnpos=b,tnsep=0pt]{\Tc*{3pt}}{%
    \TC*~{30}~[tnpos=a,tnsep=-15pt]{15}
    \TC*~{42}~[tnpos=a,tnsep=-15pt]{21}
    \TC*~{56}~[tnpos=a,tnsep=-15pt]{28}
    \TC*~{72}~[tnpos=a,tnsep=-15pt]{36}}}
\rput[b](2,-3pt){%
  \pstree[treemode=U,tnpos=a,tnsep=0pt]{\Tc*{3pt}}{%
    \TC*~{88}~[tnpos=b,tnsep=-15pt]{45}
    \TC*~{108}~[tnpos=b,tnsep=-15pt]{55}
    \TC*~{130}~[tnpos=b,tnsep=-15pt]{66}
    \TC*~{154}~[tnpos=b,tnsep=-15pt]{78}}}
\rput[t](4,3pt){%
  \pstree[radius=3pt,tnpos=b,tnsep=0pt]{\Tc*{3pt}}{%
    \TC*~{178}~[tnpos=a,tnsep=-15pt]{91}
    \TC*~{206}~[tnpos=a,tnsep=-15pt]{105}
    \TC*~{236}~[tnpos=a,tnsep=-15pt]{120}
    \TC*~{268}~[tnpos=a,tnsep=-15pt]{136}}}
% ...
\end{pspicture}

\end{document} 

enter image description here