我尝试使用 将语法树括在不断增长的双括号中\left \llbracket ... \right \rrbracket
。但是,树总是位于下半部分,而上半部分则留空,这非常丑陋……而且,我无法使尖括号随树一起增长……
\documentclass{article}
\usepackage{stmaryrd}
\usepackage{qtree}
\usepackage{tikz-qtree}
\begin{document}
$\left \llbracket \textbf{\Tree [.S [.S [ [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] ] and [.S [ [.NP [.N John ] ] [.VP [.V drinks ] ] ] ] ]} \right \rrbracket$ \\
$\left \langle \left ( \Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] \right ) \right \rangle$
\end{document}
答案1
使用baseline
选项将基线设置为与图片中心相同的高度(减去一半X高度)。
代码
\documentclass{article}
\usepackage{stmaryrd}
\usepackage{tikz-qtree}
\begin{document}
\[ \left \llbracket
\tikz[font=\bfseries, baseline={([yshift=+-.5ex]current bounding box.center)}]{
\Tree [.S [.S [ [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] ] and
[.S [ [.NP [.N John ] ] [.VP [.V drinks ] ] ] ] ]
} \right \rrbracket\]
\[ \left\langle \left(
\tikz[baseline={([yshift=+-.5ex]current bounding box.center)}]{
\Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ]}
\right) \right\rangle \]
\end{document}
输出
答案2
您还可以使用gathered
的环境amsmath
或更低级的\vcenter{\hbox{}}
构造:(但对您的\rangle
's 没有任何线索)
\documentclass{article}
\usepackage{stmaryrd}
%\usepackage{qtree}
\usepackage{tikz-qtree}
\usepackage{amsmath}
% \usepackage{forest}
\begin{document}
% here a construction with gathered and package forest for the tree
% $\left \llbracket
% \begin{gathered}
% \textbf{\begin{forest}
% [S [S [ [NP [N [Ann] ] ] [VP [V [smokes] ] ] ] ] [and] [S [[NP [N [John]
% ]] [VP [V [drinks] ] ]] ] ]
% \end{forest}}
% \end{gathered}
% \right \rrbracket$ \\
$\left \llbracket \vcenter{%
\hbox{\bfseries\Tree [.S [.S [ [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] ] and [.S [ [.NP [.N John ] ] [.VP [.V drinks ] ] ] ] ]}} \right \rrbracket$
% with gathered:
$\left \langle \left (
\begin{gathered}
\Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ]
\end{gathered}
\right ) \right \rangle$
% with \vcenter and \hbox:
$\left \langle \left (
\vcenter{%
\hbox{\Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ]}%
}
\right ) \right \rangle$
\end{document}
如果希望在同一行上有多棵树:
\documentclass{article}
\usepackage{stmaryrd}
\usepackage{tikz-qtree}
\usepackage{amsmath}
\newbox\mytreebox
\newbox\mytreeboxwithdelim
\makeatletter
\newcommand\TreeWithDelim [3]{%
\setbox\mytreebox\hbox{{#3}}%
\setbox\mytreeboxwithdelim\hbox{$#1\vcenter{\copy\mytreebox}#2$}%
\dimen@=\dimexpr\ht\mytreeboxwithdelim+\dp\mytreeboxwithdelim\relax
% in my testing, same as total height of non decorated treebox
\leavevmode\raise\dimexpr-.5\dimen@-\fontdimen22\textfont2+\ht\mytreebox\relax\box\mytreeboxwithdelim
}
\makeatother
\begin{document}
\noindent\rlap{\rule{\linewidth}{0.4pt}}%
XX\TreeWithDelim {\left\llbracket}{\right\rrbracket}
{\bfseries\Tree [.S [.S [ [.NP [.N Ann ] ] [.VP [.V smokes ] ] ] ] and [.S [ [.NP [.N John ] ] [.VP [.V drinks ] ] ] ] ]}\hfill
\TreeWithDelim {\left\langle\left(}{\right)\right\rangle}
{\Tree [.S [.NP [.N Ann ] ] [.VP [.V smokes ] ] ]}XX
\end{document}
水平规则仅用于说明目的。
答案3
这将森林与新的棺材创建树形样式
delimit tree={<left delimiter>}{<right delimiter>}
它试图保持基线正确,尽管我不确定我是否做得完全正确,所以可能需要调整。(它经过最少的测试就起作用了,但我并不真正相信它。)
有了新风格的定义,我们可以这样写
\begin{forest}
for tree={
font=\bfseries,
},
delimit tree={\left\llbracket}{\right\rrbracket}
[S
[S
[
[NP
[N
[Ann]
]
]
[VP
[V
[smokes]
]
]
]
]
[and]
[S
[
[NP
[N
[John]
]
]
[VP
[V
[drinks]
]
]
]
]
]
\end{forest}
\begin{forest}
delimit tree={\left\langle\left(}{\right)\right\rangle}
[S
[NP
[N
[Ann]
]
]
[VP
[V
[smokes]
]
]
]
\end{forest}
请注意,这保持了(我认为!)基线上树木的正确对齐。
完整代码:
\documentclass[border=10pt]{standalone}
\usepackage{stmaryrd,xcoffins}
\usepackage[linguistics]{forest}
\NewCoffin\OuterForestCoffin
\NewCoffin\InnerForestCoffin
\forestset{%
delimit tree/.code n args=2{%
\forestset{%
draw tree stage/.style={
for root'={
draw tree box=0,
draw tree,
TeX={%
\SetHorizontalCoffin\InnerForestCoffin{\box0}%
\SetHorizontalCoffin\OuterForestCoffin{%
$#1 \TypesetCoffin\InnerForestCoffin[vc,l]#2$%
}%
\TypesetCoffin\OuterForestCoffin[t,l](0pt,(\CoffinTotalHeight{\OuterForestCoffin}-\CoffinTotalHeight{\InnerForestCoffin})+\CoffinHeight{\InnerForestCoffin})%
},
},
},
}%
},
}
\begin{document}
\begin{forest}
for tree={
font=\bfseries,
},
delimit tree={\left\llbracket}{\right\rrbracket}
[S
[S
[
[NP
[N
[Ann]
]
]
[VP
[V
[smokes]
]
]
]
]
[and]
[S
[
[NP
[N
[John]
]
]
[VP
[V
[drinks]
]
]
]
]
]
\end{forest}
\begin{forest}
delimit tree={\left\langle\left(}{\right)\right\rangle}
[S
[NP
[N
[Ann]
]
]
[VP
[V
[smokes]
]
]
]
\end{forest}
\end{document}