获取行间(自动)空间以便标签可以放入其中

获取行间(自动)空间以便标签可以放入其中

我得到了绘制依存语法树的代码(使用 tikz/forest 绘制复杂的依赖关系图)。我现在为依赖关系箭头添加了标签,但看起来不太好看,因为箭头之间的空间不够。有没有办法自动为所有这些箭头及其描述获得更多空间?我认为 glaubst-dass、habe-ich 和 dass-habe 必须更高。

这就是我所拥有的:

在此处输入图片描述

\documentclass{article}

\usepackage{forest}
\usetikzlibrary{arrows.meta}
\tikzset{deparrow/.style={-Latex}}%,blue}}


\forestset{
 wg/.style={
    for tree={
      no edge,
      draw,
      outer ysep=1pt,
    },
    copy label/.style={
      for children={
        if content={}{
            content/.pgfmath={content("!u")},
            calign with current,
            edge={draw,{-Triangle[open,reversed]}},
            copy label,
            !u.content/.pgfmath={content},
            !u.content+=',
        }{
          copy label,
        }
      }
    },
    delay={
      copy label,
      for tree={name/.pgfmath={content}},
    },
    for tree={content format={\strut\forestoption{content}}},
    where n children={0}{
      tier=word,
    }{},
  },
}


    \begin{document}
\begin{forest}
  wg
  [,phantom
   [wen]
   [glaubst]
   [du]
   [dass]
   [ich]
   [gesehen]
   [habe]
  ]
\draw[deparrow] ([xshift=-0pt]glaubst.north) to[out=north, in=north] node[above] {s}     ([xshift= 0pt]du.north);
\draw[deparrow] ([xshift=-3pt]glaubst.north) to[out=north, in=north] node[above] {c}     ([xshift=-3pt]dass.north);
\draw[deparrow] ([xshift= 3pt]dass.north)    to[out=north, in=north] node[above] {c}     ([xshift= 3pt]habe.north);
\draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north] node[above] {r}     ([xshift= 0pt]gesehen.north);
\draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north] node[above] {s}     ([xshift= 0pt]ich.north);
%
\draw[deparrow] ([xshift= 0pt]gesehen.south) to[out=south, in=south] node[below] {x$<$o} ([xshift=-3pt]wen.south);
\draw[deparrow] ([xshift= 0pt]dass.south)    to[out=south, in=south] node[below] {x$<$}  ([xshift= 0pt]wen.south);
\draw[deparrow] ([xshift= 0pt]glaubst.south) to[out=south, in=south] node[below] {x$<$}  ([xshift= 3pt]wen.south);
\end{forest}

\end{document}

答案1

您可以定义贝塞尔曲线的控制点,当然,这不是自动解决方案:

\draw[deparrow] ([xshift=-0pt]glaubst.north) .. controls +(up:6mm) and +(up:6mm) .. node[above] {s}  ([xshift= 0pt]du.north);
\draw[deparrow] ([xshift=-3pt]glaubst.north) .. controls +(up:12mm) and +(up:12mm) .. node[above] {c} ([xshift=-3pt]dass.north);

答案2

另一种方法是增加looseness曲线的,这样可以保持当前语法不变。例如:

...
  \draw[deparrow] ([xshift=-3pt]glaubst.north) to[out=north, in=north, looseness=1.2] node[above] {c}     ([xshift=-3pt]dass.north);
  \draw[deparrow] ([xshift= 3pt]dass.north)    to[out=north, in=north, looseness=1.5] node[above] {c}     ([xshift= 3pt]habe.north);
...
  \draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north, looseness=1.2] node[above] {s}     ([xshift= 0pt]ich.north);

将增加looseness所讨论的三条曲线:

标签空间

完整代码:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\tikzset{deparrow/.style={-Latex}}
\forestset{
 wg/.style={
    for tree={
      no edge,
      draw,
      outer ysep=1pt,
    },
    copy label/.style={
      for children={
        if content={}{
            content/.pgfmath={content("!u")},
            calign with current,
            edge={draw,{-Triangle[open,reversed]}},
            copy label,
            !u.content/.pgfmath={content},
            !u.content+=',
        }{
          copy label,
        }
      }
    },
    delay={
      copy label,
      for tree={name/.pgfmath={content}},
    },
    for tree={content format={\strut\forestoption{content}}},
    where n children={0}{
      tier=word,
    }{},
  },
}

\begin{document}
\begin{forest}
  wg
  [,phantom
   [wen]
   [glaubst]
   [du]
   [dass]
   [ich]
   [gesehen]
   [habe]
  ]
  \draw[deparrow] ([xshift=-0pt]glaubst.north) to[out=north, in=north] node[above] {s}     ([xshift= 0pt]du.north);
  \draw[deparrow] ([xshift=-3pt]glaubst.north) to[out=north, in=north, looseness=1.2] node[above] {c}     ([xshift=-3pt]dass.north);
  \draw[deparrow] ([xshift= 3pt]dass.north)    to[out=north, in=north, looseness=1.5] node[above] {c}     ([xshift= 3pt]habe.north);
  \draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north] node[above] {r}     ([xshift= 0pt]gesehen.north);
  \draw[deparrow] ([xshift=-3pt]habe.north)    to[out=north, in=north, looseness=1.2] node[above] {s}     ([xshift= 0pt]ich.north);
  \draw[deparrow] ([xshift= 0pt]gesehen.south) to[out=south, in=south] node[below] {x$<$o} ([xshift=-3pt]wen.south);
  \draw[deparrow] ([xshift= 0pt]dass.south)    to[out=south, in=south] node[below] {x$<$}  ([xshift= 0pt]wen.south);
  \draw[deparrow] ([xshift= 0pt]glaubst.south) to[out=south, in=south] node[below] {x$<$}  ([xshift= 3pt]wen.south);
\end{forest}

\end{document}

相关内容