Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to draw a tree but unfortunately i have some childs overlap each other,I increased the sibling distance , even i have used the option scale but i have the same problem. here is my code :

\documentclass[openright,a4paper,11pt,french]{report}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning,automata,shadows,fit,shapes}

\begin{document}

\begin{tikzpicture} [scale=.6]
\tikzstyle{level 1}=[sibling distance=60mm] 
\tikzstyle{level 2}=[sibling distance=30mm] 
\tikzstyle{level 3}=[sibling distance=20mm] 

 \node{country}  
   child{node{name}child{node{ France }}}
   child{ node{city}child{node{ Paris }}}
  child{ node{region}child{node{name}child{node{ Nord-Pas De Calais }}}child{node{population}child{node{ 3996 }}}
  child{node{city}child{node{ Lille }}}}child{node{region}child{node{name}child{node{ Valle du Rhone }}}child{node{city}child{node{ Lyon }}}child{node{city}child{node{ Valence }}}}; 
 \end{tikzpicture}
  \end{document}

and the result is

enter image description here

share|improve this question
add comment

5 Answers

up vote 12 down vote accepted

Maybe not as nice looking a tree, but a lot faster to input. The tikz-qtree package is designed to optimize the spacing between nodes.

\documentclass{article}
\usepackage{tikz-qtree,tikz-qtree-compat}
\begin{document}
\begin{tikzpicture}[level 1/.style={level distance=1.5cm}]
\Tree
[.country 
  [.name France ] [.city Paris ] [.region 
                      [.name {Nord-Pas de Calais} ] 
                      [.population 3996 ] 
                      [.city Lille  ]
                   ] 
                   [.region 
                       [.name {Valle du Rhone } ] 
                      [.city Lyon ] 
                      [.city Valence ]
                  ]
]
\end{tikzpicture}
\end{document}

output of code

share|improve this answer
add comment

An answer from the future (using lualatex and incoming graphdrawing libraries from CVS version of TikZ/pgf):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphdrawing,graphdrawing.trees}
\begin{document}
\begin{tikzpicture}
  \begin{scope}%
    [tree layout,level distance=10mm,text depth=.1em,text height=.8em]
    \node{country}
    child{node{name}
      child{node{France}}
    }
    child{node{city}
      child{node{Paris}}
    }
    child{node{region}
      child{node{name}
        child{node{Nord-Pas De Calais}}
      }
      child{node{population}
        child{node{3996}}
      }
      child{node{city}
        child{node{Lille}}
      }
    }
    child{node{region}
      child{node{name}
        child{node{Vallee du Rhone}}
      }
      child{node{city}
        child{node{Lyon}}
      }
      child{node{city}
        child{node{Valence}}
      }
    }; 
  \end{scope}
\end{tikzpicture}
\end{document}

Here's the result: enter image description here

A compact version (using incoming graphs library):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,graphdrawing.trees}
\begin{document}
\begin{tikzpicture}
  \begin{scope}%
    [tree layout,level distance=10mm,text depth=.1em,text height=.8em]
    \graph[fresh nodes] {
      country -- {
        name -- France,
        city -- Paris,
        region -- {
          name -- "Nord-Pas De Calais",
          population -- 3996,
          city -- Lille
        },
        region -- {
          name -- "Valle du Rhone",
          city -- Lyon,
          city -- Valence
        }
      }
    };
  \end{scope}
\end{tikzpicture}
\end{document}
share|improve this answer
2  
So this tikz library will only work with luatex? That's an odd dependency for a library to have, IMO. –  Alan Munn Jun 20 '12 at 22:41
3  
@AlanMunn extract from incoming pgfmanual: "Unlike the rest of pgf and TikZ, which is implemented purely in TEX, the graph drawing algorithms are simply too complex to by implemented directly in TEX. Instead, the programming language Lua is used..." –  Paul Gaborit Jun 20 '12 at 22:47
2  
From a UI perspective, it might be helpful to have a \uselualibrarycommand to make the luatex requirement explicit to users. Otherwise I can see a big industry here answering "why doesn't my tikz document compile" :) (Although I guess a big console message will suffice.) –  Alan Munn Jun 20 '12 at 22:52
1  
@AlanMunn The big console message is: "! Package pgf Error: You need to run LuaTeX to use the graph drawing library." –  Paul Gaborit Jun 20 '12 at 22:56
    
Dependencies aside, the output is amazing. This is a huge gain for TikZ imho, making this much easier. –  Ingo Jan 11 at 12:10
add comment

I don't see any problems if I manually tune and do some structuring in the code. Actually if I remove the scale everything works just fine. If you want to scale the picture, you need to add transform shape option next to the scaling option.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,automata,shadows,fit,shapes}

\begin{document}

\begin{tikzpicture} %[scale=.6,transform shape] %<-- uncomment this to see the effect
\tikzstyle{level 1}=[sibling distance=52mm] 
\tikzstyle{level 2}=[sibling distance=18mm] 

 \node{country} 
  child{node{name} child{ node{ France }}}
  child{node{city} child{node{ Paris }}}
  child{node{region} 
     child{node{name}
     child{node{ Nord-Pas De Calais }}}
     child{node{population} child{node{ 3996 }}}
     child{node{city} child{node{ Lille }}}
  } 
  child{node{region}
      child{node{name}   child{node{ Valle du Rhone }}} 
      child{node{city} child{node{ Lyon }}} 
      child{node{city}child{node{ Valence }}}
  }; 
 \end{tikzpicture}
\end{document}

enter image description here

Third level sibling distance won't work if you have just one sibling for each parent.

share|improve this answer
add comment

Another option would be to use package forest, its syntax is similar, although not the same, to the one used with tikz-qtree and its main goal is to build compact trees. Take a look at next code and compare the results with the images provided by the other answerers.

Forest already loads TikZ and environment forest creates a tikzpicture.

\documentclass{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
[country 
  [name [France]] [city[ Paris ]] [region 
                      [name [Nord-Pas de Calais] ] 
                      [population [3996] ] 
                      [city [Lille]  ]
                   ] 
                   [region 
                       [name [Valle du Rhone] ] 
                      [city [Lyon] ] 
                      [city [Valence] ]
                  ]
]
\end{forest}
\end{document}

enter image description here

share|improve this answer
add comment
\documentclass[openright,a4paper,10pt,french]{report}%%

\usepackage{tikz,fullpage}
\usetikzlibrary{arrows,positioning,automata,shadows,fit,shapes}
 \usepackage{amsmath}   
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\newcommand{\highlight}[1]{%
  \ooalign{\hss\makebox[0pt]{\fcolorbox{green!30}{red!40}{$#1$}}\hss\cr\phantom{$#1$}}%
}

\begin{document}

\resizebox{\linewidth}{!}{   
\begin{tikzpicture} [font=\small]
\tikzset{level 1/.style={sibling distance=36ex}}
\tikzset{level 2/.style={sibling distance=13ex}}

 \node{country}  
  child{node{name}child{node{ France }}}
  child{ node{city}child{node{ Paris }}}
  child{ node{region}child{node{name}child{node{ Nord-Pas De Calais }}}child{node{population}child{node{ 3996 }}}
  child{node{city}child{node{ Lille }}}}child{node{region}child{node{name}child{node{ Valle du Rhone }}}child{node{city}child{node{ Lyon }}}child{node{city}child{node{ Valence }}}}; 
 \end{tikzpicture} }

  \end{document} 

enter image description here

share|improve this answer
    
why you put the document in landscape ? it doesn't work when i delete landscape –  Wassim Sboui Jun 20 '12 at 20:37
1  
I think it's difficult to put this tree on a normal page. I updated my answer –  Alain Matthes Jun 20 '12 at 21:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.