答案1
- 使用将其参数放在(文本模式)
\bracketMe
中并将和放在它周围。tabular
[
]
- 与上述相同,但通过使用通用且更加可定制的功能
\delimitMe
来自动应用\delimitMe
。 - 使用
bracket
样式键,使用自定义left delimiter
和right delimiter
功能的matrix
图书馆。
第三个选项会增加大量的 TikZ 开销(并且具有相同的可定制性),但在\bracketmatrix
无法使用的情况下可能是一个可行的解决方案(但我不知道什么时候会这样)。
代码
\documentclass[tikz]{standalone}
\usepackage{forest}
% 1.
\newcommand*\bracketMe[2][c]{$\left[\begin{tabular}{@{}#1@{}}#2\end{tabular}\right]$}
% 2.
\newcommand*\delimitMe[4]{$\left#2\begin{tabular}{@{}#1@{}}#4\end{tabular}\right#3$}
\forestset{
delimit me/.style 2 args={content/.expanded={\noexpand\delimitMe{c}{#1}{#2}{\forestoption{content}}}},
bracket me/.style={delimit me=[]}}
% 3.
\usetikzlibrary{matrix}
\makeatletter
\tikzset{
left delimiter'/.style 2 args={append after command={%
\pgfextra{\pgfmathsetlengthmacro\pgfcurrentinnerysep{\pgfkeysvalueof{/pgf/inner ysep}}}
\tikz@delimiter{east}{west}{every delimiter,every left delimiter,#2}{south}{north}{#1}{.}%
{\dimexpr\pgf@y-\pgfcurrentinnerysep*2}}},
right delimiter'/.style 2 args={append after command={%
\pgfextra{\pgfmathsetlengthmacro\pgfcurrentinnerysep{\pgfkeysvalueof{/pgf/inner ysep}}}
\tikz@delimiter{west}{east}{every delimiter,every right delimiter,#2}{south}{north}{.}{#1}%
{\dimexpr\pgf@y-\pgfcurrentinnerysep*2}}}}
\makeatother
\forestset{
left delimiter/.style 2 args={
tikz+={\path[late options={name=\forestoption{name},left delimiter'={#1}{#2}}];}},
right delimiter/.style 2 args={
tikz+={\path[late options={name=\forestoption{name},right delimiter'={#1}{#2}}];}},
lr delimiters/.style 2 args={
left delimiter/.expanded={#1}{xshift={\pgfkeysvalueof{/pgf/inner xsep}+.3333ex}},
right delimiter/.expanded={#2}{xshift={-(\pgfkeysvalueof{/pgf/inner xsep}+.3333ex)}}},
bracket/.style={lr delimiters=[]}}
\begin{document}
\begin{forest} % using \bracketmatrx
[root
[I\textsuperscript 0
[\bracketMe{MODAL\\+Tns\\+AGR}
[]
]
]
[VP
[(SPEC)]
[$\bar{\textrm{V}}$
[V\textsuperscript 0]
]
]
]
\end{forest}
\begin{forest} % using \bracketmatrix by way of bracket me
[root
[I\textsuperscript 0
[MODAL\\+Tns\\+AGR, bracket me
[]
]
]
[VP
[(SPEC)]
[$\bar{\textrm{V}}$
[V\textsuperscript 0]
]
]
]
\end{forest}
\begin{forest}% using bracket on the multiline node
[root
[I\textsuperscript 0
[MODAL\\+Tns\\+AGR, align=center, bracket
[]
]
]
[VP
[(SPEC)]
[$\bar{\textrm{V}}$
[V\textsuperscript 0]
]
]
]
\end{forest}
\end{document}
输出
答案2
看看,这是否是你在寻找的:
\documentclass[margin=3mm]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
math content,
s sep = 3mm,
l sep = 9mm,
}
[?
[I^0
[\begin{bmatrix}
\text{MODAL}\\
\text{+ Tns}\\
\text{+AGR}\end{bmatrix}]
]
[VP
[\text{(SPEC)}]
[V
[V^0]
]
]
]
\end{forest}
\end{document}