# Tikzmark between syntactic tree and matrix?

I am trying to draw a line between the S node and the matrix, but have not been able to get it to work. What am I doing wrong?

MWE:

\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}

• Please don't ask the same question twice. Instead, edit your original question to include the additional information. I've marked your other question as a potential duplicate but this is messy: this one should be the duplicate as it is newer, but it is also a much better question and now has an answer. So... Not sure what to do with it. Perhaps you could delete your other question? [Note that editing a question moves it back to the top of the front page of the site i.e. top of the queue of active questions. So you don't need to ask a new one to ensure it gets attention.] – cfr Dec 22 '14 at 17:35

This is due to the way that tikz-qtree works. The long explanation can be found at my answer to \draw alignment when connecting nodes using tikz-qtree, getting line centered

Cutting-and-pasting my code from that answer is half of the solution here. The other half is to remove the \tikzmark from the tree. Unfortunately, \tikzmark suffers from the same problem as the tikz-qtree (as explained in that answer) so it would need a similar adjustment. Fortunately, this isn't necessary. Since a tikz-qtree is inside a tikzpicture environment, we can use the ordinary tikz node labelling system to refer to nodes in a tikzpicture. (tikzmark was developed for outside a tikzpicture and actually shouldn't be used inside as it then suffers from the nested tikzpicture syndrom.)

\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}%
\pgf@process{\pgfpointorigin\subpic@parent@pos}%
\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}


It works after you switch to pdfLaTeX. For this, it's required to remove fontspec from the loaded packages.

With XeLaTeX I noticed the issue persisting.

• Is there any way to solve this problem without losing fontspec, which I need for polyglossia? – Namenlos Dec 22 '14 at 13:12
• @PRQ Would babel instead of polyglossia be an option? – Stefan Kottwitz Dec 22 '14 at 14:35
• @PRQ Have you tried LuaLaTeX? (Or babel as Stefan Kottwitz suggested.) – cfr Dec 22 '14 at 17:37
• I need to be able to input Greek characters, and babel requires too much work given the number of sentence I need to input. I have never tried LuaLaTeX, but will look into it. – Namenlos Dec 22 '14 at 17:41