我怎样才能添加“第一 第二...”?

我怎样才能添加“第一 第二...”?

在此处输入图片描述

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-qtree}
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.east)
-- +(8pt,0)
|- (\tikzchildnode)}}}
\begin{document}

\begin{tikzpicture}
\tikzset{grow'=right,level distance=32pt}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west}}
\Tree [.S [.NP [.Det the ] [.N cat ] ]
[.VP [.V sat ]
[.PP [.P on ]
[.NP [.Det the ] [.N mat ] ] ] ] ]
\end{tikzpicture}

\end{document}

答案1

你可以使用forest。但是如果你想要画很多树,你必须坐下来学习如何使用你选择的包 - 无论是tikz-qtreeqtree还是forest其他。因为你没有说什么很难,很难说出更有帮助的话。

\documentclass[border=5pt,tikz]{standalone}
\usepackage{forest}
\usetikzlibrary{positioning}

\begin{document}
\begin{forest}% initial code from Gonzalo Medina's answer at http://tex.stackexchange.com/a/56909/
  for tree={
    edge path={
      \noexpand\path [draw, thick, \forestoption{edge}] (!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};
    },
    grow'=0,
    parent anchor=east,
    child anchor=west,
    align=left,
    base=b,
    where n children=0{
      calign with current,
    }{},
    tier/.wrap pgfmath arg={tier=tier #1}{level()}
  }
  [S, name=first
    [NP, name=second
      [Det, name=top, name=third
        [the, name=fourth]
      ]
      [N
        [cat]
      ]
    ]
      [VP
        [V
          [sat]
        ]
        [PP
          [P
            [on, name=fifth]
          ]
          [NP
            [Det
              [the]
            ]
            [N
              [mat, name=sixth]
            ]
          ]
        ]
      ]
    ]
    \coordinate [above=5pt of top.north] (above);
    \foreach \i in {first, second, third, fourth, fifth, sixth}
    \node [font=\scshape\scriptsize] at (above -| \i) {\i};
\end{forest}

\end{document}

垫子上的猫

答案2

Ignasi 的回答这个问题也可以在这里轻松采用。

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{tikz-qtree}
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.east)
-- +(8pt,0)
|- (\tikzchildnode)}}}
\begin{document}

\begin{tikzpicture}
\tikzset{grow'=right,level distance=1.5cm}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west}}
\Tree [.\node(root){S}; [.\node(np){NP}; [.\node(d){Det}; \node(t){the}; ] [.N cat ] ]
[.VP [.V sat ]
[.PP [.P \node(o){on}; ]
[.NP [.Det the ] [.N \node(m){mat}; ] ] ] ] ]

\begin{scope}[every node/.style={align=left, anchor=center, font=\tiny\sffamily\bfseries,}]
 \node[above= 2mm of t] (thenode) {FOURTH};
 \node[at =(thenode-|root)] {FIRST};
 \node[at =(thenode-|np)] {SECOND};
 \node[at =(thenode-|d)] {THIRD};
 \node[at =(thenode-|o)] {FIFTH};
 \node[at =(thenode-|m)] {SIXTH};

\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容