使用 tikzpicture 和 qtree 在树中创建交叉分支

Create crossing branches in a tree using tikzpicture and qtree

为了说明一个非法的韵律结构,我需要创建一个具有交叉分支的格律结构树。我在另一篇论文(80 年代)中看到过它,我想在 Tex 中创建相同的结构,然后从那里开始工作。

Link转为图片(刚加入不能插入):https://www.pastepic.xyz/image/NtmmH

下面的代码创建了树的合法版本。我想使用类似的代码重新创建上图中的那个。

\usepackage{tikz-qtree,tikz-qtree-compat}
\begin{document}

\begin{tikzpicture} \label{tree3}
[every tree node/.style={align=center,anchor=base},sibling distance=.8cm]
\Tree [.W [.\node(S1) {\.$\Sigma$}; [.\node(s1) { $\sigma$};[.\node(fan) { fan};]]  [.\node(s2) { $\sigma$}; [.\node(ta) { ta};]]][.\node(S2) { $\Sigma$}; [.\node(s3) { $\sigma$};[.\node(fu) { fu};]]  [.\node(s4) { $\sigma$}; [.\node(cking) { cking};]]] [.\node(S3) { $\Sigma$}; [.\node(s5){ $\sigma$}; [.\node(stic){ stic};]]]]
\end{tikzpicture}

\end{document}

这是一个可能的解决方案。

想法是独立于树生成文本,这样每个字母都是一个命名节点。然后将树的节点连接到这些字母。连接可以随意规则也可以包含不规则分支

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree,tikz-qtree-compat}

\begin{document}

\begin{tikzpicture} \label{tree3}
[every tree node/.style={align=center,anchor=base},sibling distance=.8cm]
  % to avoid name clash renamed s1 to ss1, s2 to ss2 etc.
\Tree [.W [.\node(S1) {\.$\Sigma$};
            [.\node(ss1) { $\sigma$};
             %[.\node(fan) { fan};]
            ]
            [.\node(ss2) { $\sigma$};
             %[.\node(ta) { ta};]
            ]]
          [.\node(S2) { $\Sigma$};
            [.\node(ss3) { $\sigma$};
             %[.\node(fu) { fu};]
            ]
            [.\node(ss4) { $\sigma$};
             %[.\node(cking) { cking};]
            ]]
          [.\node(S3) { $\Sigma$};
            [.\node(ss5){ $\sigma$};
              %[.\node(stic){ stic};]
          ]]]

    \begin{scope}[every node/.style={inner sep=0, outer xsep=0.1mm,
                  anchor=base west}]
      % adjust outer xsep to control letter spacing
      % anchoring is done on baseline of letters to ensure proper alignment        
      \coordinate[below of=ss1, xshift=-0.3cm, yshift=0] (start);
      % The start of the text.
      %    adjust xshift and yshift to finely control text position
      % Create the letters/node names in a loop
      \foreach \l/\n [remember=\n as \prev (initially start)] in
        % the list is a letter / its node name.
        % Numbering is based on the number of the node that the 
        %   letters are connected to, in order to simplify connections
        %   so f1 is a child of node ss1 for example
        {f/f1,a/a1,n/n1,t/t2,a/a2,f/f3,u/u3,c/c4,k/k4,i/i4,n/n4,g/g4,s/s5,t/t5,i/i5,c/c5} {
        \node at (\prev.base east) (\n) {\l};
      }
    \end{scope}

  % connect a node with a leaf with proper alignment to the 
  %   taller letter (the 'f' in node f1)
  % usage to \toleaf{ss1}{f3} connect node ss1 to node f3
  % adjust yshift for the desired effect
  \def\toleaf#1#2{ (#1.south) -- ([yshift=0.1ex]#2|-f1.north) }
  % connect a node to its children node
  % Usage \toleaves{1}{f,a} connect ss1 to f1 and ss1 to a1
  % used for regular tree connections
  \def\toleaves#1#2{\foreach \n in {#2} { \toleaf{ss#1}{\n#1} }}
  \draw
    \toleaves{1}{f,a,n}
    \toleaves{2}{t,a}
    \toleaves{3}{f,u}
    \toleaves{4}{c,k,i,n,g}
    \toleaves{5}{s,t,i,c}
    %% add some crossing  branches with \toleaf
    \toleaf{ss1}{c4}
    \toleaf{ss4}{a2}
    ;
\end{tikzpicture}

\end{document}