Graphics, Figures & TablestikZ | Drawing Trees

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
leonardo1979
Posts: 4
Joined: Sat Apr 07, 2012 3:46 pm

tikZ | Drawing Trees

Post by leonardo1979 »

Hello, I am Leo, a PhD student in social science. I live in Belgium and I usually go abroad very often.

I join this group because I want to use tikZ to draw a tree. Like the code below. However I have some problems:
  1. I would like that the edges are enough long to write some words on them. As it is now, the nodes and words are almost overlapping. How may I get longer edges -BUT- avoiding that they overlap each other?
  2. I would like that the graphic is more centered (and to too much on the top).

Code: Select all

\documentclass{minimal}
\usepackage[a4paper,margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows}
\begin{document}
\begin{center}
\begin{tikzpicture}[
level 1/.style={sibling distance=95mm},
level 2/.style={sibling distance=28mm},
level 3/.style={sibling distance=20mm},
level 4/.style={sibling distance=12mm},
    fact/.style={rectangle, draw=none, rounded corners=1mm, fill=blue, drop shadow,
        text centered, anchor=north, text=white},
    state/.style={circle, draw=none, fill=orange, circular drop shadow,
        text centered, anchor=north, text=white},
    leaf/.style={circle, draw=none, fill=red, circular drop shadow,
        text centered, anchor=north, text=white},
        %level distance=3cm
]
\node {$\mathcal{N}$}
child { node {i }
%
child{ node  {j}
%
%
child{ node {x(i,j)}
edge from parent
node[left] {$\alpha_j(i)$}
}
child{node { N2 }
%
edge from parent
node[midway] {$\overline{\alpha}_j(i)$}
}
edge from parent
node[left] {$\alpha_i(j)$}
}
%
%
child{ node  {k}
child{ node {x(i,k)}
edge from parent
node[] {$\alpha_k(i)$}
}
%
child{node  { N5 }
%
edge from parent
node[] {$\overline\alpha_k(i)$}
%
}
%edge from parent
%node[left] {$\alpha_j(i.j4)$}
%
%edge from parent
%node[right] {$\alpha_j(i.j444)$}
edge from parent
node {$\alpha_i(k)$}
}
%
child{ node {j}
child{ node {k}
child{ node {x(ijk)}
edge from parent
node[left] {$\alpha_k(jk)$}
}
child{node  { N6}
edge from parent
node {$\overline\alpha_k(jk)$}
}
edge from parent
node {$\alpha_j(jk)$}
}
child{node  { k}
child{ node {N7}
edge from parent
node [] {{$\alpha_k(jk)$}}
%edge from parent
%node[right] {YYYa31}
}
child{node  { N8}
edge from parent
node [right] {$\overline\alpha_k(jk)$}
}
edge from parent
node [right] {$\overline\alpha_j(jk)$}
}
edge from parent
node [right] {$\alpha_i(j,k)$}
}
%edge from parent
%node[left] {$\alpha_j(i.j1)$}
}
child {node [state] {i,jk }
child{ node [state]{j}
child{ node {x(i,j)}}
child{node [state] { N }}
}
child{ node [state] {k}
child{ node {x(i,k)}}
child{node [state] { N }}
}
child{ node [state]{jk}
child{ node [state]{k}
child{ node {x(ijk)}
}
child{node [state] { N}}
}
child{node  { k}
child{ node [state] {N}
}
child{node [state] { N}}
}
}
}
child {node [state] {i,jk }
child{ node [state]{j}
child{ node {x(i,j)}}
child{node [state] { N }}
}
child{ node [state] {k}
child{ node {x(i,k)}}
child{node [state] { N }}
}
child{ node [state]{jk}
child{ node [state]{k}
child{ node {x(ijk)}
}
child{node [state] { N}}
}
child{[level distance=15mm]  node [state] { k}
child{ node [state] {N}
}
child{node [state] { N}}
}
}
}
;
\end{tikzpicture}
\end{center}
\end{document}
I hope I could get some advice to solve this problems.

Kindest regards

Leo
Last edited by localghost on Sat Apr 07, 2012 8:11 pm, edited 3 times in total.

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

tikZ | Drawing Trees

Post by Stefan Kottwitz »

Hi Leo,

welcome to the board!
  1. It seems that you need some more space, which means adjusting the level distance, besides the sibling distance.
  2. For vertical centering, you could insert

    Code: Select all

    \vspace*{\fill}
    before and after the image.
Stefan
LaTeX.org admin
leonardo1979
Posts: 4
Joined: Sat Apr 07, 2012 3:46 pm

Re: tikZ | Drawing Trees

Post by leonardo1979 »

Dear Stephan, thanks a lot for the advice.
Regards,
Leo
Post Reply