将过度支撑与其他 TikZ 树节点对齐

将过度支撑与其他 TikZ 树节点对齐

我正在使用该tikz-qtree包创建一棵树。\overbrace在节点中使用会更改节点的高度,但锚点不会与其对齐。使用\underbrace效果很好:

\documentclass{article}
\usepackage{tikz-qtree}

\begin{document}
Aligned:

\begin{tikzpicture}[sibling distance=0.5cm,
    level distance=1.5cm,
    growth parent anchor={north},
    nodes={anchor=north},
    empty/.style={draw=none},
    ptredlabel/.style={pos=0.75,font=\footnotesize\color{red!70!black}}]
\Tree
    [.{\color{red} $\underbrace{\color{black} (\lnot (p \wedge q) \wedge r_3)}_{\textrm{(5b) }(\alpha \wedge \beta)}$}
        \edge node[ptredlabel,auto=right] {$\alpha$};
        [.{$\color{red}\underbrace{\color{black}\lnot (p \wedge q)}_{\textrm{(5a) }\lnot \alpha}$}
        [.{$\lnot$} ]
        \edge node[ptredlabel,auto=left] {$\alpha$};
        [.{$\color{red}\underbrace{\color{black}(p \wedge q)}_{\textrm{(5b) } (\alpha \wedge \beta)}$}
        \edge node[ptredlabel,auto=right] {$\alpha$};
        [.{p} ]
            \edge node[ptredlabel,auto=left] {$\beta$};
            [.{q} ]
        ]
    ]
    \edge node[ptredlabel,auto=left] {$\beta$};
    [.{$r_3$} ]
]
\end{tikzpicture}

Not aligned:

\begin{tikzpicture}[sibling distance=0.5cm,
    level distance=1.5cm,
    growth parent anchor={north},
    nodes={anchor=north},
    empty/.style={draw=none},
    ptredlabel/.style={pos=0.75,font=\footnotesize\color{red!70!black}}]
\Tree
    [.{\color{red} $\overbrace{\color{black} (\lnot (p \wedge q) \wedge r_3)}^{\textrm{(5b) }(\alpha \wedge \beta)}$}
        \edge node[ptredlabel,auto=right] {$\alpha$};
        [.{$\color{red}\overbrace{\color{black}\lnot (p \wedge q)}^{\textrm{(5a) }\lnot \alpha}$}
        [.{$\lnot$} ]
        \edge node[ptredlabel,auto=left] {$\alpha$};
        [.{$\color{red}\overbrace{\color{black}(p \wedge q)}^{\textrm{(5b) } (\alpha \wedge \beta)}$}
        \edge node[ptredlabel,auto=right] {$\alpha$};
        [.{p} ]
            \edge node[ptredlabel,auto=left] {$\beta$};
            [.{q} ]
        ]
    ]
    \edge node[ptredlabel,auto=left] {$\beta$};
    [.{$r_3$} ]
]
\end{tikzpicture}
\end{document}

使用 \underbrace 可以工作,但使用 \overbrace 则不行。

是否可以使其工作,\overbrace以便节点的锚点位于同一级别?

答案1

如果forest是一种选择,这相当简单,可以使用手册中说明的技术(并在本网站的许多答案中有所介绍)实现半自动化。

节点在顶部对齐

\documentclass{standalone}
\usepackage[linguistics]{forest}
\begin{document}
\begin{forest}
  sn edges,
  ptredlabel/.style n args=3{% adapted from Forest manual page 84
    edge label/.expanded={node[pos=.5,ptredlabelfont,text=red!70!black,auto=#1,anchor=#2]{\strut$\unexpanded{#3}$}}},
  /tikz/ptredlabelfont/.style={font=\footnotesize},
  ptredlabelaux/.style={if n=1{ptredlabel={left}{east}{#1}}{ptredlabel={right}{west}{#1}}},
  for tree={math content, anchor=north},
  delay={
    for descendants={split option={content}{:}{content,ptredlabelaux}},
  },
  [\overbrace{\color{black} (\lnot (p \wedge q) \wedge r_3)}^{\textrm{(5b) }(\alpha \wedge \beta)}, red
    [\overbrace{\color{black}\lnot (p \wedge q)}^{\textrm{(5a) }\lnot \alpha}:\alpha, red
      [\lnot]
      [\overbrace{\color{black}(p \wedge q)}^{\textrm{(5b) } (\alpha \wedge \beta)}:\alpha, red
        [p:\alpha]
        [q:\beta]
      ]
    ]
    [r_3:\beta]
  ]
\end{forest}
\end{document}

相关内容