我正在使用该包自定义一个现成的脚本来构建决策树TikZ
,但无法以任何方式标记节点之间的连接?是否有用于标记决策树中连接的工具?此外,如何确保我的标签始终位于连接上方?我已包含代码和输出。我在输出上绘制了连接标签以显示我想要实现的目标。
\documentclass{article}
\usepackage{pgf, tikz}
\begin{document}
\begin{tikzpicture}[sibling distance=15em,
every node/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=gray!20}]]
\node {no slopes}
child { node {subj slope}
child { node {subj \& item slopes}
child { node {\textbf{max RE}} }
child { node {\textbf{subj slope}} }}
child { node {item slope}
child { node {subj \& item slopes}
child { node {\textbf{max RE}} }
child { node {\textbf{item slope}} } }
child { node {\textbf{no slopes}} } }};
\end{tikzpicture}
\end{document}
答案1
可以使用键添加连接forest
标签edge label
\documentclass{article}
\usepackage{amssymb}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={l sep+=.8cm,s sep+=.5cm,shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=gray!20}
[no slopes
[subject slope
[subj \& item slopes,for children={font=\bfseries},edge label={node[midway,left]{$\checkmark$}}
[max RE]
[subj slope]
]
[max RE,font=\bfseries,edge label={node[midway,right]{$\times$}}
[subj \& item slopes,for children={font=\bfseries}
[max RE]
[item slope]
]
[no slopes]
]
]
]
\end{forest}
\end{document}