我想将一个节点向右移动,因为它与另一个节点重合:
\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}
答案1
最好sibling distance
为每个级别一致地定义 s。我\tikzset
在下面的代码中使用了它,但您也可以将级别样式设置为环境选项tikzpicture
。
\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}