Underleaf Logo
Underleaf
PricingAboutBlog
Log InGet started

Learn TikZ

Getting Started

  • What is TikZ?
  • TikZ for Beginners
  • Basic Setup

Trees in TikZ

Create tree diagrams including binary trees, hierarchies, organization charts, and more.

Basic Tree Syntax

TikZ has built-in tree drawing capabilities using the child syntax:

\begin{tikzpicture} \node {Root} child {node {Child 1}} child {node {Child 2}}; \end{tikzpicture}

Nested Trees

\begin{tikzpicture}[ level distance=1.5cm, sibling distance=2cm ] \node {Root} child {node {A} child {node {A1}} child {node {A2}} } child {node {B} child {node {B1}} child {node {B2}} child {node {B3}} }; \end{tikzpicture}

Styled Tree Nodes

\begin{tikzpicture}[ level distance=1.5cm, sibling distance=3cm, every node/.style={ draw, circle, minimum size=8mm, fill=blue!20 }, edge from parent/.style={ draw, ->, thick } ] \node {1} child {node {2} child {node {4}} child {node {5}} } child {node {3} child {node {6}} child {node {7}} }; \end{tikzpicture}

Binary Tree

\begin{tikzpicture}[ level 1/.style={sibling distance=4cm}, level 2/.style={sibling distance=2cm}, level 3/.style={sibling distance=1cm}, every node/.style={draw, circle, minimum size=6mm} ] \node {8} child {node {4} child {node {2} child {node {1}} child {node {3}} } child {node {6} child {node {5}} child {node {7}} } } child {node {12} child {node {10} child {node {9}} child {node {11}} } child {node {14} child {node {13}} child {node {15}} } }; \end{tikzpicture}

Growing Trees in Different Directions

% Grow down (default) \begin{tikzpicture}[grow=down, level distance=1cm] \node {Root} child {node {A}} child {node {B}}; \end{tikzpicture} % Grow right (horizontal tree) \begin{tikzpicture}[grow=right, level distance=2cm, sibling distance=1cm] \node {Root} child {node {A}} child {node {B}} child {node {C}}; \end{tikzpicture} % Grow up \begin{tikzpicture}[grow=up, level distance=1cm] \node {Root} child {node {A}} child {node {B}}; \end{tikzpicture}

Organization Chart

\begin{tikzpicture}[ level 1/.style={sibling distance=4cm}, level 2/.style={sibling distance=2cm}, every node/.style={ draw, rectangle, rounded corners, minimum width=2cm, minimum height=0.8cm, text centered, font=\small }, edge from parent/.style={draw, -} ] \node[fill=red!30] {CEO} child {node[fill=blue!20] {CTO} child {node[fill=green!20] {Dev Lead}} child {node[fill=green!20] {QA Lead}} } child {node[fill=blue!20] {CFO} child {node[fill=green!20] {Accounting}} } child {node[fill=blue!20] {COO} child {node[fill=green!20] {HR}} child {node[fill=green!20] {Operations}} }; \end{tikzpicture}

File System Tree

\begin{tikzpicture}[ grow via three points={ one child at (0.5,-0.7) and two children at (0.5,-0.7) and (0.5,-1.4) }, edge from parent path={ (\tikzparentnode.south) |- (\tikzchildnode.west) }, every node/.style={anchor=west, font=\ttfamily} ] \node {project/} child {node {src/} child {node {components/} child {node {Header.tsx}} child {node {Footer.tsx}} } child {node {pages/} child {node {index.tsx}} child {node {about.tsx}} } child {node {utils/} child {node {helpers.ts}} } } child {node {public/} child {node {images/}} } child {node {package.json}} child {node {README.md}}; \end{tikzpicture}

Decision Tree

\begin{tikzpicture}[ level 1/.style={sibling distance=5cm}, level 2/.style={sibling distance=2.5cm}, decision/.style={draw, diamond, aspect=2, fill=yellow!30}, outcome/.style={draw, rectangle, rounded corners, fill=green!20}, edge from parent/.style={draw, ->, thick}, edge label/.style={font=\footnotesize} ] \node[decision] {Weather?} child {node[decision] {Weekend?} child {node[outcome] {Stay home} edge from parent node[left, edge label] {No} } child {node[outcome] {Go hiking} edge from parent node[right, edge label] {Yes} } edge from parent node[left, edge label] {Sunny} } child {node[decision] {Have work?} child {node[outcome] {Work} edge from parent node[left, edge label] {Yes} } child {node[outcome] {Read book} edge from parent node[right, edge label] {No} } edge from parent node[right, edge label] {Rainy} }; \end{tikzpicture}

Using the Trees Library

\usetikzlibrary{trees} \begin{tikzpicture}[ grow cyclic, level 1/.style={level distance=2cm, sibling angle=120}, level 2/.style={level distance=1.5cm, sibling angle=45}, every node/.style={draw, circle, fill=blue!20} ] \node {A} child {node {B} child {node {D}} child {node {E}} } child {node {C} child {node {F}} child {node {G}} } child {node {H} child {node {I}} child {node {J}} }; \end{tikzpicture}

Empty Branches (Missing Children)

\begin{tikzpicture}[ level distance=1.5cm, sibling distance=2cm, every node/.style={draw, circle} ] \node {5} child {node {3} child {node {1}} child[missing] % Empty right child } child {node {7} child[missing] % Empty left child child {node {9}} }; \end{tikzpicture}

Custom Edge Styles

\begin{tikzpicture}[ level distance=1.5cm, sibling distance=3cm, every node/.style={draw, rectangle, rounded corners} ] \node {Root} child { node {Left} edge from parent[dashed, red] } child { node {Right} edge from parent[thick, blue, ->] }; \end{tikzpicture}

Next Steps

Continue learning TikZ diagrams:

  • Graphs - Network and graph diagrams
  • Mind Maps - Concept mapping diagrams
  • Flowcharts - Process flow diagrams

Trees in TikZ

Create tree diagrams including binary trees, hierarchies, organization charts, and more.

Basic Tree Syntax

TikZ has built-in tree drawing capabilities using the child syntax:

\begin{tikzpicture} \node {Root} child {node {Child 1}} child {node {Child 2}}; \end{tikzpicture}

Nested Trees

\begin{tikzpicture}[ level distance=1.5cm, sibling distance=2cm ] \node {Root} child {node {A} child {node {A1}} child {node {A2}} } child {node {B} child {node {B1}} child {node {B2}} child {node {B3}} }; \end{tikzpicture}

Styled Tree Nodes

\begin{tikzpicture}[ level distance=1.5cm, sibling distance=3cm, every node/.style={ draw, circle, minimum size=8mm, fill=blue!20 }, edge from parent/.style={ draw, ->, thick } ] \node {1} child {node {2} child {node {4}} child {node {5}} } child {node {3} child {node {6}} child {node {7}} }; \end{tikzpicture}

Binary Tree

\begin{tikzpicture}[ level 1/.style={sibling distance=4cm}, level 2/.style={sibling distance=2cm}, level 3/.style={sibling distance=1cm}, every node/.style={draw, circle, minimum size=6mm} ] \node {8} child {node {4} child {node {2} child {node {1}} child {node {3}} } child {node {6} child {node {5}} child {node {7}} } } child {node {12} child {node {10} child {node {9}} child {node {11}} } child {node {14} child {node {13}} child {node {15}} } }; \end{tikzpicture}

Growing Trees in Different Directions

% Grow down (default) \begin{tikzpicture}[grow=down, level distance=1cm] \node {Root} child {node {A}} child {node {B}}; \end{tikzpicture} % Grow right (horizontal tree) \begin{tikzpicture}[grow=right, level distance=2cm, sibling distance=1cm] \node {Root} child {node {A}} child {node {B}} child {node {C}}; \end{tikzpicture} % Grow up \begin{tikzpicture}[grow=up, level distance=1cm] \node {Root} child {node {A}} child {node {B}}; \end{tikzpicture}

Organization Chart

\begin{tikzpicture}[ level 1/.style={sibling distance=4cm}, level 2/.style={sibling distance=2cm}, every node/.style={ draw, rectangle, rounded corners, minimum width=2cm, minimum height=0.8cm, text centered, font=\small }, edge from parent/.style={draw, -} ] \node[fill=red!30] {CEO} child {node[fill=blue!20] {CTO} child {node[fill=green!20] {Dev Lead}} child {node[fill=green!20] {QA Lead}} } child {node[fill=blue!20] {CFO} child {node[fill=green!20] {Accounting}} } child {node[fill=blue!20] {COO} child {node[fill=green!20] {HR}} child {node[fill=green!20] {Operations}} }; \end{tikzpicture}

File System Tree

\begin{tikzpicture}[ grow via three points={ one child at (0.5,-0.7) and two children at (0.5,-0.7) and (0.5,-1.4) }, edge from parent path={ (\tikzparentnode.south) |- (\tikzchildnode.west) }, every node/.style={anchor=west, font=\ttfamily} ] \node {project/} child {node {src/} child {node {components/} child {node {Header.tsx}} child {node {Footer.tsx}} } child {node {pages/} child {node {index.tsx}} child {node {about.tsx}} } child {node {utils/} child {node {helpers.ts}} } } child {node {public/} child {node {images/}} } child {node {package.json}} child {node {README.md}}; \end{tikzpicture}

Decision Tree

\begin{tikzpicture}[ level 1/.style={sibling distance=5cm}, level 2/.style={sibling distance=2.5cm}, decision/.style={draw, diamond, aspect=2, fill=yellow!30}, outcome/.style={draw, rectangle, rounded corners, fill=green!20}, edge from parent/.style={draw, ->, thick}, edge label/.style={font=\footnotesize} ] \node[decision] {Weather?} child {node[decision] {Weekend?} child {node[outcome] {Stay home} edge from parent node[left, edge label] {No} } child {node[outcome] {Go hiking} edge from parent node[right, edge label] {Yes} } edge from parent node[left, edge label] {Sunny} } child {node[decision] {Have work?} child {node[outcome] {Work} edge from parent node[left, edge label] {Yes} } child {node[outcome] {Read book} edge from parent node[right, edge label] {No} } edge from parent node[right, edge label] {Rainy} }; \end{tikzpicture}

Using the Trees Library

\usetikzlibrary{trees} \begin{tikzpicture}[ grow cyclic, level 1/.style={level distance=2cm, sibling angle=120}, level 2/.style={level distance=1.5cm, sibling angle=45}, every node/.style={draw, circle, fill=blue!20} ] \node {A} child {node {B} child {node {D}} child {node {E}} } child {node {C} child {node {F}} child {node {G}} } child {node {H} child {node {I}} child {node {J}} }; \end{tikzpicture}

Empty Branches (Missing Children)

\begin{tikzpicture}[ level distance=1.5cm, sibling distance=2cm, every node/.style={draw, circle} ] \node {5} child {node {3} child {node {1}} child[missing] % Empty right child } child {node {7} child[missing] % Empty left child child {node {9}} }; \end{tikzpicture}

Custom Edge Styles

\begin{tikzpicture}[ level distance=1.5cm, sibling distance=3cm, every node/.style={draw, rectangle, rounded corners} ] \node {Root} child { node {Left} edge from parent[dashed, red] } child { node {Right} edge from parent[thick, blue, ->] }; \end{tikzpicture}

Next Steps

Continue learning TikZ diagrams:

Underleaf Logo
Underleaf

Empowering students and researchers with AI-powered tools for academic writing.

Go to appContact us

Company

PricingBlogTutorialsAffiliate Program

Free Tools

Image to LaTeXExcel to LaTeXArXiv to LaTeXTikZ GeneratorThesis GeneratorChrome ExtensionAll Tools

© 2026 Underleaf. All rights reserved.