我想排版
因此,我写道(推导https://tex.stackexchange.com/a/302713/82730)
\documentclass[a4size]{article}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}
% forest
\usepackage{forest}
% parsing tree
\forestset{
declare toks={wff}{},
declare toks={connective}{},
declare dimen register={parsing tree sep},
parsing tree sep=7.5pt,
parsing tree/.style={
% append the current root to a new phantom root.
for root'={
replace by={[,phantom,append=!last dynamic node]}
},
for tree={
math content,
parent anchor=children,
child anchor=parent,
inner sep=0pt,
if n children=1{!first.before packing=calign with current edge}{},
delay={
content=\circ,
insert before/.wrap pgfmath arg={
[##1,no edge,math content,anchor=base east, before computing xy={
s/.pgfmath={s("!n")-parsing_tree_sep}}]
}{wff},
if connective={}{connective/.option=wff}{},
insert after/.wrap pgfmath arg={
[##1,no edge,math content,anchor=base west, before computing xy={
s/.pgfmath={s("!p")+parsing_tree_sep}}]
}{connective}
}
}
},
default preamble={parsing tree,baseline}
}
\begin{document}
\begin{center}
\fbox{
\begin{adjustbox}{valign=M}
\begin{forest}
[,wff=1,connective=\chi]
\end{forest}
\qquad
\begin{forest}
[,wff=m+3,connective=\neg [,wff=m,connective=\chi]]
\end{forest}
\qquad
\begin{forest}
[,wff=m+n+3,connective=\neg [,wff=m,connective=\chi]
[,wff=n,connective=\chi]]
\end{forest}
\end{adjustbox}
}
\end{center}
\end{document}
呈现为
左侧的树未垂直居中,但它位于顶部。如何使树垂直居中?
答案1
根据定义,只有一个框,没有其他对齐参考,因此所有树都是顶部对齐的。选择将每棵树放在单独的框上,并选择中间对齐,即M
垂直中心(高度和深度相等),我们得到了所需的结果。类似于:
\begin{adjustbox}{valign=M} <content> \end{adjustbox}\qquad\begin{adjustbox}{valign=M} <content> \end{adjustbox}\qquad\begin{adjustbox}{valign=M} <content> \end{adjustbox}
以下是我:
\documentclass[a4size]{article}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}
% forest
\usepackage{forest}
% parsing tree
\forestset{
declare toks={wff}{},
declare toks={connective}{},
declare dimen register={parsing tree sep},
parsing tree sep=7.5pt,
parsing tree/.style={
% append the current root to a new phantom root.
for root'={
replace by={[,phantom,append=!last dynamic node]}
},
for tree={
math content,
parent anchor=children,
child anchor=parent,
inner sep=0pt,
if n children=1{!first.before packing=calign with current edge}{},
delay={
content=\circ,
insert before/.wrap pgfmath arg={
[##1,no edge,math content,anchor=base east, before computing xy={
s/.pgfmath={s("!n")-parsing_tree_sep}}]
}{wff},
if connective={}{connective/.option=wff}{},
insert after/.wrap pgfmath arg={
[##1,no edge,math content,anchor=base west, before computing xy={
s/.pgfmath={s("!p")+parsing_tree_sep}}]
}{connective}
}
}
},
default preamble={parsing tree,baseline}
}
\begin{document}
\begin{center}
\fbox{
\begin{adjustbox}{valign=M}
\begin{forest}
[,wff=1,connective=\chi]
\end{forest}
\end{adjustbox}
\qquad
\begin{adjustbox}{valign=M}
\begin{forest}
[,wff=m+3,connective=\neg [,wff=m,connective=\chi]]
\end{forest}
\end{adjustbox}
\qquad
\begin{adjustbox}{valign=M}
\begin{forest}
[,wff=m+n+3,connective=\neg [,wff=m,connective=\chi]
[,wff=n,connective=\chi]]
\end{forest}
\end{adjustbox}
}
\end{center}
\end{document}
其他方法涉及使用表格格式。例如:
\begin{tabular}{m{0.25\textwidth}m{0.25\textwidth}m{0.25\textwidth}@{}m{0pt}@{}}
\begin{forest}
[,wff=1,connective=\chi]
\end{forest}
&
\begin{forest}
[,wff=m+3,connective=\neg [,wff=m,connective=\chi]]
\end{forest}
&
\begin{forest}
[,wff=m+n+3,connective=\neg [,wff=m,connective=\chi]
[,wff=n,connective=\chi]]
\end{forest}
&
\end{tabular}
答案2
你不需要不同的盒子等。你只需要移除baseline
并使用 TikZ 的baseline
选项将树垂直居中。例如,
\documentclass[]{article}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{adjustbox}
% forest
\usepackage{forest}
% parsing tree
\forestset{
declare toks={wff}{},
declare toks={connective}{},
declare dimen register={parsing tree sep},
parsing tree sep=7.5pt,
parsing tree/.style={
% append the current root to a new phantom root.
for root'={
replace by={[,phantom,append=!last dynamic node]}
},
for tree={
math content,
parent anchor=children,
child anchor=parent,
inner sep=0pt,
if n children=1{!first.before packing=calign with current edge}{},
delay={
content=\circ,
insert before/.wrap pgfmath arg={
[##1,no edge,math content,anchor=base east, before computing xy={
s/.pgfmath={s("!n")-parsing_tree_sep}}]
}{wff},
if connective={}{connective/.option=wff}{},
insert after/.wrap pgfmath arg={
[##1,no edge,math content,anchor=base west, before computing xy={
s/.pgfmath={s("!p")+parsing_tree_sep}}]
}{connective}
}
},
/tikz/baseline=(current bounding box.center)
},
default preamble={parsing tree}
}
\begin{document}
\begin{center}
\fbox{
\begin{adjustbox}{valign=M}
\begin{forest}
[,wff=1,connective=\chi]
\end{forest}
\qquad
\begin{forest}
[,wff=m+3,connective=\neg [,wff=m,connective=\chi]]
\end{forest}
\qquad
\begin{forest}
[,wff=m+n+3,connective=\neg [,wff=m,connective=\chi]
[,wff=n,connective=\chi]]
\end{forest}
\end{adjustbox}
}
\end{center}
\end{document}
请注意,这a4size
不是一个有效的选项,因此我将其删除,因为它没有区别。也许你的意思是a4paper
?在这种情况下,你应该确保geometry
使用标准类加载类似的东西。