我正在尝试排版一个等式,其中等式元素是使用二叉树的表达式。但我的等式的布局很糟糕,括号位置不正确,二叉树到处都是。我希望有人能帮我做一个更好的等式。
\documentclass{article}
\oddsidemargin 43pt
\textheight 20.4 cm
\textwidth 14.0 cm
\parskip 6.8 pt
\parindent 12 pt
\usepackage{tikz}
\begin{document}
\begin{equation}
\hspace{-12mm}
\begin{tikzpicture}[%
level distance=7.5mm,
level 1/.style={sibling distance=30mm},
level 2/.style={sibling distance=15mm},
level 3/.style={sibling distance=7.5mm},
level 4/.style={sibling distance=3.75mm}
baseline=(current bounding box.center)]
\node (a) {$a$}
child {node (b1) {$b$}
child{node(c1) {$c$}
child{node(d1) {$T$}}
child{node(d2) {$F$}}
}
child{node(c1) {$c$}
child{node(d1) {$T$}}
child{node(d2) {$F$}}
}
}
child {node (b2) {$F$}}
;
\end{tikzpicture}
= T \land \left (
\begin{tikzpicture}[%
level distance=7.5mm,
level 1/.style={sibling distance=15mm},
level 2/.style={sibling distance=7.5mm},
level 3/.style={sibling distance=3.75mm}
baseline=(current bounding box.center)]
\node (a) {$a$}
child {node (b1) {$b$}
child{node(c1) {$T$}}
child{node(c1) {$T$}}
}
child {node (b2) {$F$}}
;
\end{tikzpicture}
\land
\begin{tikzpicture}[%
level distance=7.5mm,
level 1/.style={sibling distance=15mm},
level 2/.style={sibling distance=7.5mm},
level 3/.style={sibling distance=3.75mm}
baseline=(current bounding box.center)]
\node (a) {$c$}
child {node (b1) {$T$}}
child {node (b2) {$F$}}
;
\end{tikzpicture}
\right )
\end{equation}
\end{document}
答案1
使用forest
和adjustbox
包的替代解决方案:
\documentclass{article}
\usepackage{forest}
\usepackage{adjustbox}
\begin{document}
\begin{equation}
\forestset{
default preamble={
for tree={l sep=3mm, s sep=2mm, math content}}
}
\adjustbox{valign=c}{\begin{forest}
[a
[b,fit=band
[c
[T]
[F]
]
[c
[T]
[F]
]
]
[F]
]
\end{forest}}
= T \land \left(\hspace{-1.2em}
\adjustbox{valign=c}{\begin{forest}
[a
[b
[T]
[F]
]
[F]
]
\end{forest}}
\land
\adjustbox{valign=c}{\begin{forest}
[c
[T]
[F]
]
\end{forest}}
\right)
\end{equation}
\end{document}
答案2
这是Zarko 的回答,它使用 进行对齐,baseline
而不是加载adjustbox
。(我赶紧补充说,我不知道没有理由不加载adjustbox
,所以这总体上没有什么特别的优势。)
我以稍微不同的方式对它们进行排列,因为我发现这样树更容易阅读,但这很大程度上取决于偏好、背景和内容。
\documentclass[border=9pt]{article}
\usepackage{forest}
\begin{document}
\begin{equation}
\forestset{
default preamble={
for tree={l sep'=3mm, s sep'=2mm, math content},
delay={!r1.baseline}
}
}
\begin{forest}
[a
[b,fit=band
[c
[T]
[F]
]
[c
[T]
[F]
]
]
[F]
]
\end{forest}
= T \land \left(
\begin{forest}
[a
[b
[T]
[F]
]
[F]
]
\end{forest}
\land
\begin{forest}
[c
[T]
[F]
]
\end{forest}
\right)
\end{equation}
\end{document}