![修复重叠决策树](https://linux22.com/image/426726/%E4%BF%AE%E5%A4%8D%E9%87%8D%E5%8F%A0%E5%86%B3%E7%AD%96%E6%A0%91.png)
能否帮助我修复决策树中的重叠。您能建议一个更好的代码吗?
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\tikzset{
treenode/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=blue!20},
root/.style = {treenode, font=\Large, bottom color=red!30},
env/.style = {treenode, font=\ttfamily\normalsize},
dummy/.style = {circle,draw}
}
\begin{document}
\begin{tikzpicture}
[
grow = right,
sibling distance = 8em,
level distance = 8em,
edge from parent/.style = {draw, -latex},
every node/.style = {font=\footnotesize},
sloped
]
\node [root] {Venture to start}
child { node [env] {Restaurant}
child { node [env] {-\$30}
edge from parent node [below] {50\% Fail} }
child { node [env] {\$sssss100}
edge from parent node [above, align=center] {50\% success}}
edge from parent node [above] {} }
child { node [env] {Coffee Shop}
child { node [env] {-\$30}
edge from parent node [below] {50\% Fail} }
child { node [env] {\$00}
edge from parent node [above, align=center]
{50\% success}
node [below] {}}
edge from parent node [above] {} };
\end{tikzpicture}
\end{document}
答案1
您可以通过添加yshift=...
选项来本地调整单个节点,例如
node [env,yshift=15] {-\$30}
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\tikzset{
treenode/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=blue!20},
root/.style = {treenode, font=\Large, bottom color=red!30},
env/.style = {treenode, font=\ttfamily\normalsize},
dummy/.style = {circle,draw}
}
\begin{document}
\begin{tikzpicture}
[
grow = right,
sibling distance = 8em,
level distance = 8em,
edge from parent/.style = {draw, -latex},
every node/.style = {font=\footnotesize},
sloped
]
\node [root] {Venture to start}
child { node [env] {Restaurant}
child { node [env] {-\$30}
edge from parent node [below] {50\% Fail} }
child { node [env,yshift=-15] {\$100}
edge from parent node [above, align=center] {50\% success}}
edge from parent node [above] {} }
child { node [env] {Coffee Shop}
child { node [env,yshift=15] {-\$30}
edge from parent node [below] {50\% Fail} }
child { node [env] {\$00}
edge from parent node [above, align=center]
{50\% success}
node [below] {}}
edge from parent node [above] {} };
\end{tikzpicture}
\end{document}