我想使用森林在每个节点的右侧添加一个标签。
\tikzset{
rect/.append style={rectangle, align=center,rounded corners=2pt, label={[fill=yellow,font=\tiny]0:#1}, font=\tiny, draw=black},
}
\begin{forest}
for tree={
s sep=0.1cm,
font=\sffamily\bfseries,
line width=0.5pt,
rect,
child anchor=north,
parent anchor=south,
l sep+=12.5pt,
edge path={
\noexpand\path[rounded corners=5pt, line width=0.5pt, ->, \forestoption{edge}]
(!u.parent anchor) -- +(0,-5pt) -|
(.child anchor)\forestoption{edge label};
},
}
[ Parent, label=My label
[Variant 1 ]
[Variant 2 ]
]
\end{forest}
我想把“我的标签”放入黄色框中
谢谢
答案1
您可以使用rect
样式并将文本作为参数传递:
\documentclass{article}
\usepackage{forest}
\begin{document}
\tikzset{
rect/.append style={rectangle, align=center,rounded corners=2pt, label={[fill=yellow,font=\tiny]0:#1}, font=\tiny, draw=black},
}
\begin{forest}
for tree={
s sep=2cm,
font=\sffamily\bfseries,
line width=0.5pt,
%rect,
child anchor=north,
parent anchor=south,
l sep+=12.5pt,
edge path={
\noexpand\path[rounded corners=5pt, line width=0.5pt, ->, \forestoption{edge}]
(!u.parent anchor) -- +(0,-5pt) -|
(.child anchor)\forestoption{edge label};
},
}
[ Parent,rect={some test text}
[Variant 1,rect={some test text} ]
[Variant 2,rect={some test text} ]
]
\end{forest}
\end{document}