我想在子树上添加一个矩形,如下图所示。该怎么做?
这是forest
代码。
\documentclass{article}
\usepackage{forest}
\useforestlibrary{linguistics}
\begin{document}
\pagestyle{empty}
\begin{forest}
for tree = {
sn edges,
grow'=0,
l=2.5cm,
s sep=0.2cm,
anchor=west,
child anchor=west}
[
[O
[R
[T]
]
[T
[R]
]
]
[R
[O
[T]
]
[T
[O]
]
]
[T
[O
[R]
]
[R
[O]
]
]
]
\end{forest}
\end{document}
答案1
您可以在中为节点分配名称forest
,因此您可以将其与 Tikzfit
库一起使用在您选择的节点周围绘制一个节点。
如果您不想使用节点,您也可以这样做(不需要任何库):
\draw[red,thick] (bottomright.south east) rectangle (left.west|-topright.north);
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage{forest}
\useforestlibrary{linguistics}
\usetikzlibrary{fit}
\begin{document}
\begin{forest}
for tree = {
sn edges,
grow'=0,
l=2.5cm,
s sep=0.2cm,
anchor=west,
child anchor=west}
[
[O,name=left
[R
[T,name=topright]
]
[T
[R,name=bottomright]
]
]
[R
[O
[T]
]
[T
[O]
]
]
[T
[O
[R]
]
[R
[O]
]
]
]
\node[draw=red,thick,fit=(left)(topright)(bottomright)] {};
\end{forest}
\end{document}