具有水平终端节点和空节点的较短树(带森林)

具有水平终端节点和空节点的较短树(带森林)

我正在向 ACL 风格的期刊提交一篇计算论文。我需要具有水平对齐终端节点且没有节点标签的树(解析器不提供它们)。这个问题与这个;我从一些评论中获取了代码(稍作更新),结果树足够短,可以适合我的论文,但它们非常丑陋。

梅威瑟:

\documentclass[11pt,letterpaper]{article}
\usepackage[letterpaper]{geometry}
\usepackage{acl2012}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{amsmath}
\usepackage{forest}
\forestset{
nice empty nodes/.style={
    for tree={
        s sep=0.1em, 
        l sep=0.33em,
        inner ysep=0.4em, 
        inner xsep=0.05em,
        l=0,
        calign=midpoint,
        fit=tight,
        where n children=0{
           tier=word,
           minimum height=1.25em,
        }{},
        where n children=2{
           l-=1em,
        }{},
        parent anchor=south,
        child anchor=north,
        delay={if content={}{
                inner sep=0pt,
                edge path={\noexpand\path [\forestoption{edge}] 
                            (!u.parent anchor) 
                           -- (.south)\forestoption{edge label};}
            }{}}
    },
},
}

\begin{document}
\begin{forest}
 nice empty nodes
[ [ [ [He] [swung] ] [ [at] [the] ] ] [ [ [brute] [\textbf{with}] ] [ [\textbf{his}] [, phantom ] [ [\textbf{sword}] [$.$] ] ] ] ]
\end{forest}

\begin{forest}
 nice empty nodes
[ [He] [ [ [ [swung] [ [at] [ [the] [brute] ] ] ] [ [\textbf{with}] [ [\textbf{his}] [\textbf{sword}] ] ] ] [$.$] ] ]
\end{forest}%
\end{document}

它生成了以下两棵树: 我的树看起来像大象......

我花了大约 15 个小时来解决这个问题,我们小组的其他 3 或 4 个人也一样,所以这似乎是一个难题......

要求:

  1. 根节点与最左和最右终端节点之间的直线
  2. 垂直方向上尽可能小的树
  3. 单词间距不要太大(不必完全均匀)
  4. 根据符号高度的变化(例如句号和高字母)改变线深度不会发生奇怪的事情

可能看起来像下一棵树,但不需要那么多的手动 tikz 时间并且在垂直方向上不是那么高......

小宝宝 tikz 绘制的树

有什么建议吗?

答案1

坦白说,Forest 不擅长绘制这种风格的树。这意味着任何解决方案都会做出妥协,并且只对有限种类的树有效。

(4)很简单。考虑到 Forest 绘制树的方式,其余要求本质上是不一致的。

以下列出几种可能性。

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\forestset{
  somewhat nice/.style={
    for tree={
      fit=band,
      parent anchor=children,
      child anchor=parent,
      anchor=parent,
      delay={
        if content={}{
          inner sep=0pt,
          edge path'={(!u.parent anchor) -- (.children)},
        }{content/.wrap value=\strut ##1},
      },
    },
    before drawing tree={
      tempdima/.min={y}{tree},
      where n children=0{y/.register=tempdima}{},     
    },
    before computing xy={
      for tree={
        l/.process={ dOw+nw2+d  {40pt} {level} {##1+1} {##1/##2} }
      }
    }
  },
}
\begin{document}
\begin{forest}
 somewhat nice
 [ [ [ [He] [swung] ] [ [at] [the] ] ] [ [ [brute] [\textbf{with}] ] [ [\textbf{his}] [, phantom ] [ [\textbf{sword}] [$.$] ] ] ] ]
\end{forest}

\begin{forest}
 somewhat nice
 [ [He] [ [ [ [swung] [ [at] [ [the] [brute] ] ] ] [ [\textbf{with}] [ [\textbf{his}] [\textbf{sword}] ] ] ] [$.$] ] ]
\end{forest}

\end{document}

有点好

我认为,考虑到所涉及的困难,这对第一棵树来说还不错。它改善了第二棵树,尽管程度较小。

或者,可能,

有点好 & 有点好

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\forestset{
  declare dimen register={base ht},
  base ht'=40pt,
  somewhat nice/.style={
    for tree={
      fit=band,
      parent anchor=children,
      child anchor=parent,
      anchor=parent,
      delay={
        if content={}{
          inner sep=0pt,
          edge path'={(!u.parent anchor) -- (.children)},
        }{content/.wrap value=\strut ##1},
      },
    },
    before drawing tree={
      tempdima/.min={y}{tree},
      where n children=0{y/.register=tempdima}{},     
    },
    before computing xy={
      for tree={
        l/.process={ ROw+nw2+d  {base ht} {level} {##1+1} {##1/##2} }
      }
    }
  },
}
\begin{document}
\begin{forest}
 somewhat nice
 [ [ [ [He] [swung] ] [ [at] [the] ] ] [ [ [brute] [\textbf{with}] ] [ [\textbf{his}] [, phantom ] [ [\textbf{sword}] [$.$] ] ] ] ]
\end{forest}

\begin{forest}
  base ht'=30pt,
  somewhat nice,
  for tree={
    calign=fixed edge angles, 
    calign angle=40,
  },
  before packing={
    for nodewalk={
      r,
      while nodewalk valid={1}{1},
      fake=r,
      while nodewalk valid={l}{l}
    }{calign angle=60},
  }
  [ [He] [ [ [ [swung] [ [at] [ [the] [brute] ] ] ] [ [\textbf{with}] [ [\textbf{his}] [\textbf{sword}] ] ] ] [$.$] ] ]
\end{forest}

\end{document}

相关内容