能否帮助我修复决策树中的重叠。您能建议一个更好的代码吗?
\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}