林木的线角和空间

林木的线角和空间

我正在尝试使用以下方法创建以下树forest

在此处输入图片描述

我得到了这个:

\documentclass{article}
\usepackage{forest, amsmath}
\begin{document}
    \begin{forest}
        for tree = {%
            parent anchor = south,
            child anchor = north,
            s sep = 0em}
        [, phantom
            [, phantom
                [h, no edge, tier  = segment]
            ]
            [{[$-$R]}, calign = first
                [a, tier  = segment]
                [v, no edge, tier  = segment]
                [r, no edge, tier  = segment]
            ]
            [{[+R]}, calign = midpoint
                [, parent anchor = north
                    [$\stackrel{*}{\text{u}}$, tier  = segment]
                    [z, no edge, tier  = segment]
                    [u, tier  = segment]
                ]
                    [n, no edge, tier  = segment]
                    [u, tier  = segment]
                    [z, no edge, tier  = segment]
            ]
            [{[$-$R]}, calign = last
                [d, no edge, tier  = segment]
                [$\stackrel{*}{\text{a}}$, tier  = segment]
            ]           
        ]
    \end{forest}
\end{document}

在此处输入图片描述

看起来还不错,但我想改进两点:

  1. h第一个段和下一个段之间有很大的间隙a(此外,底层所有段之间也有太多空间,但我可以忍受)。
  2. 下方的分支结构[+R]理想情况下应该是直线,这样当树有分支时线的角度就不会改变。

我怎样才能实现这两件事?

答案1

您的愿望冲突。我们可以用来calign=fixed edge angles拉直中间子树的边缘。但是,这将需要扩展子节点,这将增加最后一行字母之间的间距。

直边与间隔开的孩子

或者,我们可以保持终端子元素的间距或多或少固定,但边缘就不能是直的。

边缘弯曲的舒适儿童

如果您需要两者,那么您可能必须假装。

用直边假装舒适的孩子

\documentclass[border=10pt]{standalone}
\usepackage[linguistics]{forest}
\usepackage{amsmath}
\begin{document}
\begin{forest}
  for tree={
    s sep'=0em,    
  },
  before typesetting nodes={
    where content={}{child anchor=center, parent anchor=center}{},
    where n children=0{tier=segment, inner sep=0pt}{},
  },
  [, phantom
    [{[$-$R]}
      [h, no edge]
      [a, calign with current edge]
      [v, no edge]
      [r, no edge]
    ]
    [{[+R]}, for tree={calign=fixed edge angles}
      [
        [$\stackrel{*}{\text{u}}$]
        [z, no edge]
        [u]
      ]
      [n, no edge]
      [u]
      [z, no edge]
    ]
    [{[$-$R]}
      [d, no edge]
      [$\stackrel{*}{\text{a}}$, calign with current edge]
    ]           
  ]
\end{forest}
\begin{forest}
  for tree={
    s sep'=0em,    
    inner sep=0pt,
  },
  before typesetting nodes={
    where content={}{coordinate}{},
    where n children=0{tier=segment}{},
  },
  [, phantom
    [{[$-$R]}
      [h, no edge]
      [a, calign with current edge]
      [v, no edge]
      [r, no edge]
    ]
    [{[+R]}
      [
        [$\stackrel{*}{\text{u}}$]
        [z, no edge]
        [u]
      ]
      [n, no edge]
      [u]
      [z, no edge]
    ]
    [{[$-$R]}
      [d, no edge]
      [$\stackrel{*}{\text{a}}$, calign with current edge]
    ]           
  ]
\end{forest}
\begin{forest}
  for tree={
    s sep'=0em,    
    inner sep=0pt,
  },
  before typesetting nodes={
    where content={}{coordinate}{},
    where n children=0{tier=segment}{},
  },
  [, phantom
    [{[$-$R]}
      [h, no edge]
      [a, calign with current edge]
      [v, no edge]
      [r, no edge]
    ]
    [{[+R]}, tikz+={
      \draw [\forestoption{edge}] (.parent anchor) -- (!11.child anchor) coordinate [midway] (p) (p) -- (!1l.child anchor);
    }
      [, for tree={no edge}
        [$\stackrel{*}{\text{u}}$]
        [z]
        [u]
      ]
      [n, no edge]
      [u]
      [z, no edge]
    ]
    [{[$-$R]}
      [d, no edge]
      [$\stackrel{*}{\text{a}}$, calign with current edge]
    ]           
  ]
\end{forest}
\end{document}

相关内容