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 want to shift a node to the right because it coincides with another node:

no description

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}

\begin{tikzpicture}[sibling distance=2.5cm, level distance=2.5cm]
\node {S}
  child {[dotted]  node {\{E.v:=0\}}}
  child {  node {E}
  child{[dotted]  node {\{T.v:=1\}}}
  child {  node {T}
  child {  node {F}
  child {  node {NB}}
  child{[dotted]  node {\{F.v:=SR(NB)\}}}}
  child{[dotted]  node {\{T.v:=T.v*F.r\}}}
  child [sibling distance=2cm]{  node {R2}
  child  {  node {$\varepsilon$}}}}
  child{[dotted]  node {\{E.v:=E.v+T.v\}}}
  child {  node {R1}
  child[sibling distance=0.8cm]{[dotted]  node {\{T.v:=1\}}}
  child [sibling distance=0.5cm]{  node {+}}
  child {  node {T}
  child {  node {F}
  child {  node {NB}}
  child{[dotted]  node {\{F.v:=SR(NB)\}}}}}
  child{[dotted]  node {\{E.v:=E.v+T.v\}}}
  child {  node {R1}
  child {  node {$\varepsilon$}}} }}
;
\end{tikzpicture}

\end{document} 

enter image description here

share|improve this question

1 Answer 1

up vote 3 down vote accepted

It's probably better to define the sibling distances consistently for each level. I used \tikzset in the following code, but you can also set the level styles as options to the tikzpicture environment.

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}

\begin{tikzpicture}[level distance=2.5cm]

% Setting sibling distance for each level of the tree
\tikzset{
  level 1/.style={sibling distance=4cm},
  level 2/.style={sibling distance=3.5cm},
  level 3/.style={sibling distance=1.8cm},
}

\node {S}
  child {[dotted]  node {\{E.v:=0\}}}
  child {  node {E}
  child{[dotted]  node {\{T.v:=1\}}}
  child {  node {T}
  child {  node {F}
  child {  node {NB}}
  child{[dotted]  node {\{F.v:=SR(NB)\}}}}
  child{[dotted]  node {\{T.v:=T.v*F.r\}}}
  child {  node {R2}
  child  {  node {$\varepsilon$}}}}
  child{[dotted]  node {\{E.v:=E.v+T.v\}}}
  child {  node {R1}
  child {[dotted]  node {\{T.v:=1\}}}
  child {  node {+}}
  child {  node {T}
  child {  node {F}
  child {  node {NB}}
  child{[dotted]  node {\{F.v:=SR(NB)\}}}}}
  child{[dotted]  node {\{E.v:=E.v+T.v\}}}
  child {  node {R1}
  child {  node {$\varepsilon$}}} }}
;
\end{tikzpicture}

\end{document} 
share|improve this answer
    
thank you,but I have another problem(see the initial tree) –  GoldRay May 2 '13 at 22:39
1  
@user29570: Updated the answer. Is this what you're looking for? –  Kevin C May 2 '13 at 23:12
    
thank you very much .How can I change the color of interrupted lines?to red –  GoldRay May 2 '13 at 23:19
1  
@user29570: after the node{...}, add edge from parent[red] –  Kevin C May 2 '13 at 23:21

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.