句法树和矩阵之间的 Tikzmark?

句法树和矩阵之间的 Tikzmark?

我试图在 S 节点和矩阵之间画一条线,但无法让它工作。我做错了什么?

梅威瑟:

\documentclass[a4paper,12pt]{article}


\usepackage{fontspec,tikz, tikz-qtree, multicol,avm,array}

\usetikzlibrary{matrix, positioning, trees, calc, arrows, fit,tikzmark,positioning}

\begin{document}


\begin{multicols}{2}

\begin{tikzpicture}
\begin{scope}
\Tree [.\tikzmark{S}{S} [.NP [.Det the ]
[.N cat ] ]
[.VP [.V sat ]
[.PP [.P on ]
[.NP [.Det the ]
[.N; mat ] ] ] ] ]
\end{scope}
\end{tikzpicture}

\columnbreak

\begin{avm}
\scriptsize
\[{} \tikzmark{PRED}{PRED} `avoid <SUBJ, OBJ>'; TNS $\neq$ PAST \cr
      TOPIC \[ PRED `kind<COMP>' \cr
                    DEF +; LOC FAR; NUM SG \cr
                    COMP \[ PRED `of <OBJ>' \cr
                            OBJ \[ PRED `cake'\] \] \]\tikzmark{topic} \cr
     SUBJ \[ PRED `pro'; NUM SG; PERS 1; CASE NOM\] \cr
      OBJ \[ $\qquad$ \]\tikzmark{object} \cr
     ADJ \[ PRED `usually'\] \]
\end{avm}

\begin{tikzpicture}[remember picture,overlay] 
    \draw[->] (pic cs:S)--(pic cs:PRED);
    \draw[-] (pic cs:topic) to[out=0,in=0,looseness=2]  (pic cs:object);
\end{tikzpicture}
\end{multicols}

\end{document}

答案1

这是由于工作方式所致tikz-qtree。详细解释可参见我的答案\使用 tikz-qtree 连接节点时绘制对齐​​,使线居中

从该答案中剪切并粘贴我的代码是解决方案的一半。另一半是\tikzmark从树中删除。不幸的是,\tikzmark遭受与相同的问题tikz-qtree(如该答案中所述),因此需要进行类似的调整。幸运的是,这不是必要的。由于 atikz-qtreetikzpicture环境中,我们可以使用普通tikz节点标签系统来引用 a 中的节点tikzpicture。(tikzmark是为外部a tikzpicture,实际上不应该在内部使用,因为它会受到嵌套 tikzpicture 综合症

\documentclass[a4paper,12pt]{article}
%\url{https://tex.stackexchange.com/q/219072/86}

\usepackage{fontspec,tikz, tikz-qtree, multicol,avm,array}

\usetikzlibrary{matrix, positioning, trees, calc, arrows, fit,tikzmark,positioning}
\makeatletter

\def\unwind@subpic#1{%
% is #1 the current picture?
\edef\subpicid{#1}%
\ifx\subpicid\pgfpictureid
% yes, we're done
\else
% does #1 have a parent picture?
\expandafter\ifx\csname pgf@sh@pi@#1\endcsname\relax
% no, the original node was not inside the current picture
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
\pgfsys@getposition{\pgfpictureid}\pgf@shape@current@pos
\pgf@process{\pgfpointorigin\pgf@shape@current@pos}%
\advance\pgf@xa by-\pgf@x%
\advance\pgf@ya by-\pgf@y%
\pgf@process{\pgfpointorigin\subpic@parent@pos}%
\advance\pgf@xa by \pgf@x%
\advance\pgf@ya by \pgf@y%
\pgf@x=\pgf@xa
\pgf@y=\pgf@ya
\else
% yes, apply transform, save picture location, and move up to parent picture
\pgfsys@getposition{\csname pgf@sh@pi@#1\endcsname}\subpic@parent@pos%
{%
  \pgfsettransform{\csname pgf@sh@nt@#1\endcsname}%
  \pgf@pos@transform{\pgf@x}{\pgf@y}%
  \global\pgf@x=\pgf@x
  \global\pgf@y=\pgf@y
}%
\unwind@subpic{\csname pgf@sh@pi@#1\endcsname}%
\fi
\fi
}


\def\pgf@shape@interpictureshift#1{%
\def\subpic@parent@pos{\pgfpointorigin}%
\unwind@subpic{\csname pgf@sh@pi@#1\endcsname}%
}

\makeatother
\begin{document}


\begin{multicols}{2}

\begin{tikzpicture}[remember picture]
\begin{scope}
\Tree [. \node (S) {S}; [.NP [.Det the ]
[.N cat ] ]
[.VP [.V sat ]
[.PP [.P on ]
[.NP [.Det the ]
[.N; mat ] ] ] ] ]
\end{scope}
\end{tikzpicture}

\columnbreak

\begin{avm}
\scriptsize
\[{} \tikzmark{PRED}{PRED} `avoid <SUBJ, OBJ>'; TNS $\neq$ PAST \cr
      TOPIC \[ PRED `kind<COMP>' \cr
                    DEF +; LOC FAR; NUM SG \cr
                    COMP \[ PRED `of <OBJ>' \cr
                            OBJ \[ PRED `cake'\] \] \]\tikzmark{topic} \cr
     SUBJ \[ PRED `pro'; NUM SG; PERS 1; CASE NOM\] \cr
      OBJ \[ $\qquad$ \]\tikzmark{object} \cr
     ADJ \[ PRED `usually'\] \]
\end{avm}

\begin{tikzpicture}[remember picture,overlay] 
\draw[->] (S)--(pic cs:PRED);
    \draw[-] (pic cs:topic) to[out=0,in=0,looseness=2]  (pic cs:object);
\end{tikzpicture}
\end{multicols}

\end{document}

答案2

切换到 pdfLaTeX 后即可使用。为此,需要fontspec从已加载的包中删除。

使用 XeLaTeX 时我注意到该问题仍然存在。

相关内容