1

What is a simple solution to prevent overlapping in tikzpicture. I tried changing sibling distance and level distance but as you can see in my code / picture euqation2 is not visible because it's under equation1.

 \documentclass[oneside, english, 12pt]{book}
 \usepackage[a4paper]{geometry}
 \usepackage[bitstream-charter]{mathdesign}
 \usepackage{tikz}

 \tikzset{
 treenode/.style = {shape=rectangle, rounded corners,
                 draw, align=center,
                 top color=white, bottom color=blue!30!white},
 root/.style     = {treenode, font=\Large, bottom color=red!20!white},
 env/.style      = {treenode, font=\ttfamily\normalsize},
 dummy/.style    = {circle,draw}
 }   
\begin{document}
  \begin{tikzpicture} [
 grow                    = right,
 sibling distance        = 15em,
 level distance          = 10em,
 edge from parent/.style = {draw, -latex},
 every node/.style       = {font=\footnotesize},
sloped ]         
\node [root] {Formula}                                                                      
  child { node [dummy] {}
     child { node [env] {equation1}
       edge from parent node [below] {single-line?} }
     child { node [env] {equation2}
       edge from parent node [below] {multi-line?} }}
  child { node [dummy] {}
    child { node [env] {equation3}
      edge from parent node [above] {at several}
                       node [below] {places?} }
    child { node [env] {equation4}
            edge from parent node [above] {centered?} } };
  \end{tikzpicture}
  \end{document}

enter image description here

1
  • 1
    You might want to post a full MWE that compiles on its own. This way your chances for someone providing an answer are much higher
    – Dux
    Commented Mar 14, 2016 at 11:11

2 Answers 2

2

You can e.g. add:

level 1/.style={sibling distance = 15em},
level 2/.style={sibling distance = 10em},

in the tikzpicture options, so that no overlap occurs.

0
0

If you are prepared to use another package, Forest handles the layout of nodes in trees automatically, although you need to adjust the distance between levels a little to make space for the labels. Its tree syntax is also much more concise and it tends to produce quite space-efficient trees by default.

For example:

\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{forest}
\usepackage[bitstream-charter]{mathdesign}
\tikzset{%
  treenode/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=blue!30!white},
  root/.style     = {treenode, font=\Large, bottom color=red!20!white},
  env/.style      = {treenode, font=\ttfamily\normalsize},
  dummy/.style    = {circle, draw}
}
\begin{document}
\begin{forest}
  over label/.style={%
    edge label+={node [midway, above, anchor=south, sloped, font=\footnotesize] {#1}},
  },
  under label/.style={%
    edge label+={node [midway, below, anchor=north, sloped, font=\footnotesize] {#1}},
  },
  for tree={
    grow = east,
    edge={-latex},
    calign=fixed angles,
    l sep=5em,
  }
  [Formula, root
    [, dummy
      [equation1, env, under label={single line?}
      ]
      [equation2, env, under label={multi-line?}
      ]
    ]
    [, dummy
      [equation3, env, over label={at several}, under label=places
      ]
      [equation4, env, over label={centred?}
      ]
    ]
  ]
\end{forest}
\end{document}

forest option

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .