我无法包围两个节点
\documentclass{standalone}
\usepackage[utf8]{inputenc} %unicode support
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage{forest}
\usetikzlibrary{arrows.meta, angles}
\begin{document}
\forestset{
circ/.style={
label={[circle, draw, anchor=south]south:#1}
}
}
\begin{forest}
for tree={
edge={-},
l sep+=7.5pt
},
[Foo
[Bar1, circ=T, name=b1]
[Bar2, circ=F, name=b2]
[qux1, circ=T, name=q1]
]
\node[draw,rounded rectangle,fit={ (b1) (b2) }, yshift=-0.5cm] {};
\end{forest}
\end{document}
我想圈出Bar1,Bar2和它们对应的圆圈
感谢您的帮助
答案1
您可以做类似的事情,尽管这很尴尬并且不太直观,因为当在 TikZ 选项中指定它们时(无论是隐式还是显式),很难按正确的顺序执行它们。所以它相当混乱。
也许我忽略了一个更明显的策略。(我想我必须缺少更明显的策略!)
\documentclass[border=10pt,tikz,multi]{standalone}
\usepackage{forest}
\usetikzlibrary{fit}
\begin{document}
\forestset{%
declare count register={clabel},
clabel'=0,
circ/.style={%
clabel'+=1,
tikz+/.wrap pgfmath arg={%
\node (label ##1) [circle, draw, anchor=north] at (.south) {#1};
}{clabel()},
},
}
\begin{forest}
for tree={%
l sep+=7.5pt,
delay={%
content/.wrap value={\strut #1},
}
},
[Foo
[Bar1, circ=T, name=b1]
[Bar2, circ=F, name=b2]
[qux1, circ=T, name=q1, tikz+={\node[draw, rounded rectangle, fit=(b1) (b2) (label 1) (label 2), inner xsep=-5pt, inner ysep=1pt] {};}]
]
\end{forest}
\end{document}