![如何在我的树形图中添加一片叶子?](https://linux22.com/image/333264/%E5%A6%82%E4%BD%95%E5%9C%A8%E6%88%91%E7%9A%84%E6%A0%91%E5%BD%A2%E5%9B%BE%E4%B8%AD%E6%B7%BB%E5%8A%A0%E4%B8%80%E7%89%87%E5%8F%B6%E5%AD%90%EF%BC%9F.png)
\documentclass{article}
\usepackage{qtree}
\begin{document}
\Tree [.X leaf_1 [.Y leaf_2 [.Z leaf_3 last !{\qbalance} ] ] ]
\end{document}
我想在 leaf_1 下添加一个叶子和节点。我该怎么做?
还有一个问题,我怎样才能编写与图表平行的文本?
节点周围是否可以有框架,就像圆形节点一样?
我正在尝试创建类似的东西
编辑2:我尝试通过删除学生节点和链接到它的所有叶子来修改它,但是我的代码出现错误,
\begin{forest}
shade me/.style={%
bottom color=#1!25,
top color=#1!5,
draw=#1,
drop shadow,
font=\sffamily,
},
my label/.style n args=2{%
edge label={node [midway, black, font=\sffamily\scriptsize, #1] {#2}}
},
where n children=0{%
shade me=blue!50!cyan,
}{%
if level=0{%
shade me=green!75!gray,
}{%
shade me=blue!75!magenta,
}
},
for tree={%
delay={content/.wrap value={\strut #1}},
edge={red,->},
l sep+=25pt,
s sep+=20pt
}
[Debt
[Age, my label={above, sloped}{High}
[No, my label={above, sloped}{$< 30$}]
[Yes, my label={above, sloped}{$31\dots 40$}]
]
[CR, my label={above, sloped}{Low}
[Yes, my label={above, sloped}{Fair}]
[Age, my label={above, sloped}{Excellent}
[No, my label={above, sloped}{$> 40$}]
[Yes, my label={above, sloped}{$31\dots 40$}]]
]
]
\end{forest}
答案1
你想要这个吗?
\documentclass{article}
\usepackage{qtree}
\begin{document}
\Tree [.X [.leaf_1 leaf_4 node ] [.Y leaf_2 [.Z leaf_3 last !{\qbalance} ] ] ]
\end{document}
对于更漂亮的树,您需要一个更漂亮的包。以下是使用 Forest 的示例:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{shadows}
\begin{document}
\begin{forest}
shade me/.style={%
bottom color=#1!25,
top color=#1!5,
draw=#1,
drop shadow,
font=\sffamily,
},
my label/.style n args=2{%
edge label={node [midway, black, font=\sffamily\scriptsize, #1] {#2}}
},
where n children=0{%
shade me=blue!50!cyan,
}{%
if level=0{%
shade me=green!75!gray,
}{%
shade me=blue!75!magenta,
}
},
for tree={%
delay={content/.wrap value={\strut #1}},
edge={red,->},
l sep+=25pt,
s sep+=20pt
}
[Income
[Age, my label={above, sloped}{High}
[No, my label={above, sloped}{$< 30$}]
[Yes, my label={above, sloped}{$31\dots 40$}]
]
[Student, my label={}{Medium}
[Age
[No, my label={above, sloped}{$< 30$}]
[Yes, my label={above, sloped}{$31\dots 40$}]
[CR, my label={above, sloped}{$> 40$}
[Yes, my label={above, sloped}{Fair}]
[No, my label={above, sloped}{Excellent}]
]
]
[Yes]
]
[CR, my label={above, sloped}{Low}
[Yes, my label={above, sloped}{Fair}]
[Age, my label={above, sloped}{Excellent}
[No, my label={above, sloped}{$> 40$}]
[Yes, my label={above, sloped}{$31\dots 40$}]]
]
]
]
\end{forest}
\end{document}