我怎样才能使下面的决策树清晰易读?
代码如下:
\begin{forest}
for tree={l sep+=.8cm,s sep+=.5cm,shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=gray!20}
[Root,edge label={node[midway,left]{z=0}}
[Unacceptable,edge label={node[midway,left]{Safety=Low}}
]
[Split on Doors,edge label={node[midway,left]{Safety=Medium}}
[Unacceptable,for children={font=\bfseries},edge label=
{node[midway,left]{Doors=2}} ]
[Acceptable,for children={font=\bfseries},edge label=
{node[midway,left]{Doors=3}} ]
[Good,for children={font=\bfseries},edge label={node[midway,left]
{Doors=4}} ]
[Split on Lugboot,for children={font=\bfseries},edge label=
{node[midway,left]{Doors=5more}}
[Acceptable,for children={font=\bfseries},edge label=
{node[midway,left]{Lugboot=Small}} ]
[Good,for children={font=\bfseries},edge label={node[midway,left]
{Lugboot=Medium}} ]
[Good,for children={font=\bfseries},edge label={node[midway,left]
{Lugboot=Big}} ]
]
]
[Split on lugboot,edge label={node[midway,left]{Safety=High}}
[Split on Persons,for children={font=\bfseries},edge label={node[midway,left]{Small}}
[Unacceptable,edge label={node[midway,left]{Persons=2}}
]
[Good,edge label={node[midway,left]{Persons=4}}
]
[Good,edge label={node[midway,left]{Persons=5more}}
]
]
[Vgood,for children={font=\bfseries},edge label={node[midway,left]{Medium}} ]
[Vgood,for children={font=\bfseries},edge label={node[midway,left]
{Big}} ]
]
]
\end{forest}
答案1
目前尚不清楚您的限制是什么,但以下内容肯定清晰易读。
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
l sep'+=.8cm,
s sep'+=.5cm,
rounded corners,
draw,
align=center,
top color=white,
bottom color=gray!20,
},
forked edges,
my label/.style={
edge label={
node [midway, below right, align=center] {#1}
},
}
[Root,edge label={node[midway,left]{z=0}}
[Unacceptable, my label={Safety=Low}
]
[Split on Doors, my label={Safety=Medium}
[Unacceptable,for children={font=\bfseries}, my label={Doors=2}
]
[Acceptable,for children={font=\bfseries}, my label={Doors=3}
]
[Good,for children={font=\bfseries}, my label={Doors=4}
]
[Split on Lugboot,for children={font=\bfseries}, my label={Doors=5more}
[Acceptable,for children={font=\bfseries}, my label={Lugboot\\=Small} ]
[Good,for children={font=\bfseries}, my label={Lugboot\\=Medium} ]
[Good,for children={font=\bfseries}, my label={Lugboot\\=Big} ]
]
]
[Split on lugboot, my label={Safety=High}
[Split on Persons,for children={font=\bfseries}, my label={Small}
[Unacceptable, my label={Persons=2}
]
[Good, my label={Persons=4}
]
[Good, my label={Persons=5more}
]
]
[Vgood,for children={font=\bfseries}, my label={Medium} ]
[Vgood,for children={font=\bfseries}, my label={Big} ]
]
]
\end{forest}
\end{document}