Graphics, Figures & TablesText and lines in a data-structure tree

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jhapk
Posts: 81
Joined: Tue Apr 20, 2010 9:33 pm

Text and lines in a data-structure tree

Post by jhapk »

Hi,

I want to make a tree like this
tree.png
tree.png (22.19 KiB) Viewed 2037 times
However, my code gives me the following output
latex_output.png
latex_output.png (21.83 KiB) Viewed 2037 times
Here is my code

Code: Select all

\documentclass[12pt]{minimal}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}

\begin{tikzpicture}
  [level distance=15mm,
  every node/.style={fill=black, rectangle, minimum size=2pt},
  level 1/.style={sibling distance=10mm},
  level 2/.style={sibling distance=0.5*10mm},
  level 3/.style={sibling distance=0.3*10mm}] 

  \node {}[grow=up]   
  child {node {}}
  child { node {}
    child {node {}}
    child { node {}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node [above] {D}}
      child {node {}}
      child {node {}}
    }
    child {node {}}
    child {node {}}
    child {node {}}
    child {node {}}
    child {node {}}
    child {node {}}
  }
  child {node {}}
  child {node {}}
  child {node {}}
  child { node {}
    child {node [above] {C}}
    child {node {}}
    child {node {}}
    child {node {}}
    child {node {}}
    child { node {}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
    }
    child {node {}}
    child {node {}}
  }
  child {node [above] {B}}
  child {node {}};
   
\end{tikzpicture}
\end{document}
Any ideas how do I place additional lines and text in the same scope and how do I place text on top of some desired node?

Thanks
Last edited by jhapk on Tue Sep 21, 2010 4:34 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Text and lines in a data-structure tree

Post by localghost »

Place appropriate nodes with the according text subsequently.


Best regards
Thorsten
jhapk
Posts: 81
Joined: Tue Apr 20, 2010 9:33 pm

Text and lines in a data-structure tree

Post by jhapk »

Hi,

Thanks localghost. That solved the problem. The present code gives me the desired tree structure.

Code: Select all

\documentclass{minimal}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  [level distance=15mm,
  every node/.style={fill=black, rectangle, minimum size=2pt},
  level 1/.style={sibling distance=10mm},
  level 2/.style={sibling distance=0.5*10mm},
  level 3/.style={sibling distance=0.3*10mm}]  

  \node {}[grow=up]	
  child {node {}}
  child { node {}
    child {node {}}
    child { node {}
      child {node {}}
      child {node {}} 
      child {node {}}
      child {node {}}
      child {node {}}
      child {node (D) {}}
      child {node {}}
      child {node {}}
    }
    child {node {}}
    child {node {}}
    child {node {}}
    child {node {}}
    child {node {}}
    child {node {}}
  }
  child {node {}}
  child {node {}}
  child {node {}}
  child { node {}
    child {node (C) {}}
    child {node {}}
    child {node {}}
    child {node {}}
    child {node {}}
    child { node {}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
      child {node {}}
    }
    child {node {}}
    child {node {}}
  }
  child {node (B) {}}
  child {node {}};

  \draw (0,0) -- (0,-1) -- (-5,-1) -- (-5,0) node [at end] (A) {};

  \node [above,fill=white] at (A.north) {A};
  \node [above,fill=white] at (B.north) {B};
  \node [above,fill=white] at (C.north) {C}; 
  \node [above,fill=white] at (D.north) {D}; 

  \node [fill=white] at (-6.5,0) {0};
  \node [fill=white] at (-6.5,15mm) {1};
  \node [fill=white] at (-6.5,2*15mm) {2};
  \node [fill=white] at (-6.5,3*15mm) {3};

  \node [fill=white] at (-6.5,3.5*15mm) {Refinement Level};
  \node [fill=white] at (0,3.5*15mm) {Octree};

\end{tikzpicture}

\end{document}
Post Reply