绘制指向树中节点的箭头

绘制指向树中节点的箭头

我试着画出以下三个图形。左边的只是符号序列 NP V NP AP,中间的是一个一元分支树,右边的是一个二元分支树。我想在相应的项下方放置一个 V,并用箭头将 V 连接到最左边图中的 V 到中间图中的下方 V 以及右图中的右下方 V。我想有一种简单的方法(或几种方法)可以做到这一点。

\documentclass{scrbook} 

\usepackage{tikz-qtree}
\tikzset{every roof node/.append style={inner sep=0.1pt,text height=2ex,text depth=0.3ex}}

\newcommand{\sliste}[1]{%
\mbox{%
$\left\langle\mbox{\scshape #1}\right\rangle$}%
}

\newcommand{\trace}{\raisebox{0.2ex}{\_}\rule{0cm}{0.7em}}



\begin{document}

\begin{figure}[htbp]
\hfill
\begin{tikzpicture}[baseline=(construction.base)]
\draw (0,0) node {V} -- (0,1) node (construction) {NP V NP AP};
\end{tikzpicture}
\hfill
\begin{tikzpicture}[baseline=(V.base)]
\Tree[.\node (V) {V \sliste{ NP, NP, AP }}; \node (v-in) {V \sliste{ NP }}; ]
\node (v-lex) {V};
\draw (v-lex) (v-in);
\end{tikzpicture}
\hfill
\begin{tikzpicture}[baseline=(V.base)]
\Tree[.\node (V) {V \sliste{ NP, NP, AP }};
        [.{V \sliste{ NP, NP, AP, [1] }} \trace{} ]
        \node (v-in) {[1] V \sliste{ NP }}; ]
\node (v-lex) {V};
\draw (v-lex) (v-in);
\end{tikzpicture}


\hfill\mbox{}
\caption{\label{phrasal-lexical-empty}Phrasal analysis, lexical analysis and analysis with an empty head}
\end{figure}

\end{document}

答案1

新更新:

如果希望使用 3 个独立tikzpicture环境,则可以通过以下代码实现。

\documentclass{article} 
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\usepackage{tikz-qtree}
\tikzset{every roof node/.append style={inner sep=0.1pt,text height=2ex,text depth=0.3ex}}

\newcommand{\sliste}[1]{%
\mbox{%
$\left\langle\mbox{\scshape #1}\right\rangle$}%
}

\newcommand{\trace}{\raisebox{0.2ex}{\_}\rule{0cm}{0.7em}}
\thispagestyle{empty}
\begin{document}

\tikzset{line/.style={<->,>=stealth}}  % new style for conneting lines
\begin{figure}[!htbp]
\centering

\raisebox{1.5cm}{
\begin{tikzpicture}%[yshift=5cm]
\Tree[.\node (construction) {\phantom{$\langle$}NP V NP AP\phantom{$\rangle$}}; ]
\node[below =0.5cm of construction,xshift=-2ex] (left) {V};
\draw[line] (left.north)  to ([xshift=-2ex]construction.south);
\end{tikzpicture}
}
\begin{tikzpicture}%[xshift=3cm]
\Tree[.\node (V)    {V \sliste{ NP, NP, AP }}; 
          \node (v-in) {V \sliste{ NP }}; ]
\node[below = 2cm of V] (middle) {V};
\draw [line] (middle.north) to ([xshift=-3ex]v-in.south);
\end{tikzpicture}
\begin{tikzpicture}%[xshift=8cm]
\Tree[.\node (V) {V \sliste{ NP, NP, AP }};
        [.{V \sliste{ NP, NP, AP, [1] }} ]
        \node (v-in) {[1] V \sliste{ NP }}; ]
\node [below=2cm of V](right) {V};
\draw [line]  (right.north) to ([xshift=-3ex]v-in.south);
\end{tikzpicture}
\caption{\label{phrasal-lexical-empty}Phrasal analysis, lexical analysis and analysis with an empty head}
\end{figure}

\end{document}

根据下面 OP 的评论,连接与第一个建议不同。由于非常指定的 V 有其内部标签left, middle, right,因此此更新通过以下命令使用它们来连接其上级 v

\draw [name1.north] to ([yshift=-<dim>]name2.south);

在此处输入图片描述

代码

\documentclass{article} 
%\usepackage[papersize={20cm,6cm}]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\usepackage{tikz-qtree}
\tikzset{every roof node/.append style={inner sep=0.1pt,text height=2ex,text depth=0.3ex}}

\newcommand{\sliste}[1]{%
\mbox{%
$\left\langle\mbox{\scshape #1}\right\rangle$}%
}

\newcommand{\trace}{\raisebox{0.2ex}{\_}\rule{0cm}{0.7em}}
\thispagestyle{empty}
\begin{document}

\tikzset{line/.style={<->,>=stealth}}  % or >=latex' :new style for connecting lines
\begin{figure}[htbp]
\begin{center}
\begin{tikzpicture}
\begin{scope}
\Tree[.\node (construction) {\phantom{$\langle$}NP V NP AP\phantom{$\rangle$}}; ]
\node[below =2cm of construction] (left) {V};
\draw[line] (left.north)  to ([xshift=-2ex]construction.south);
\end{scope}

\begin{scope}[xshift=3cm]
\Tree[.\node (V)    {V \sliste{ NP, NP, AP }}; 
          \node (v-in) {V \sliste{ NP }}; ]
\node[below = 2cm of V] (middle) {V};
\draw [line] (middle.north) to ([xshift=-3ex]v-in.south);
\end{scope}

\begin{scope}[xshift=8cm]
\Tree[.\node (V) {V \sliste{ NP, NP, AP }};
        [.{V \sliste{ NP, NP, AP, [1] }} ]
        \node (v-in) {[1] V \sliste{ NP }}; ]
\node [below=2cm of V](right) {V};
\draw [line]  (right.north) to ([xshift=-3ex]v-in.south);
\end{scope}
\end{tikzpicture}
\hfill\mbox{}
\caption{\label{phrasal-lexical-empty}Phrasal analysis, lexical analysis and analysis with an empty head}
\end{center}
\end{figure}

\end{document}

这是使用环境在选项中scope放置三个图形的尝试。此外,每个图形下方的 V 的位置是通过tikz 中的库确定的。xshift=xx<dim>scopepositioning
在此处输入图片描述

   Code

        \documentclass{article} 
        \usepackage{tikz}
        \usetikzlibrary{positioning}
        \usepackage{tikz-qtree}
        \tikzset{every roof node/.append style={inner sep=0.1pt,text height=2ex,text depth=0.3ex}}

        \newcommand{\sliste}[1]{%
        \mbox{%
        $\left\langle\mbox{\scshape #1}\right\rangle$}%
        }

        \newcommand{\trace}{\raisebox{0.2ex}{\_}\rule{0cm}{0.7em}}
        \thispagestyle{empty}
        \begin{document}


        \begin{figure}[htbp]
        \begin{center}
        \begin{tikzpicture}
        \begin{scope}
        \Tree[.\node (construction) {\phantom{$\langle$}NP V NP AP\phantom{$\rangle$}}; ]
        \node[below =2cm of construction] (left) {V};
        \end{scope}

        \begin{scope}[xshift=3cm]
        \Tree[.\node (V)    {V \sliste{ NP, NP, AP }}; 
                  \node (v-in) {V \sliste{ NP }}; ]
        \node[below = 2cm of V] (middle) {V};
        \draw [<->] (left) to (middle);
        \end{scope}

        \begin{scope}[xshift=8cm]
        \Tree[.\node (V) {V \sliste{ NP, NP, AP }};
                [.{V \sliste{ NP, NP, AP, [1] }} ]
                \node (v-in) {[1] V \sliste{ NP }}; ]
        \node [below=2cm of V](right) {V};
        \draw [<->]  (middle) to (right);
        \end{scope}
        \end{tikzpicture}
        \hfill\mbox{}
        \caption{\label{phrasal-lexical-empty}Phrasal analysis, lexical analysis and analysis with an empty head}
        \end{center}
        \end{figure}

        \end{document}

相关内容