1

I try to connect parts of nodes in a foresttree to other parts of nodes. This worked in texlive 2013. I had an answer to my problem, which is also documented in Having two forest figures and using tikzmark. Later I got a solution with subnode:

\documentclass{article}
\usepackage{forest}

\usetikzlibrary{tikzmark}


\begin{document}


\begin{forest}
[V
[\subnode{ap1}{AP}
[ungewaschen]]
[V{[ \subnode{arg11}{1}, \subnode{arg12}{2} ]}
[isst]]]
\end{forest}
\begin{tikzpicture}[overlay,remember picture]
\draw[->, bend angle=40, bend left] (ap1.north) to (arg11.north);
\draw[->, bend angle=40, bend left] (ap1.north) to (arg12.north); 
\end{tikzpicture}

\end{document}

enter image description here

But none of these solutions works in texlive 2014 and 2015. I now got an answer to another question that requires tex live 2015 and hence I am stuck. So the question is is there a library or anything else that allows one to have nodes within forest nodes? I guess this is really crucial for linguistics. The forest manual has some code for drawing arrows, but not for subparts of nodes.

pdflatex gets it right, but xelatex produces the following picture:

enter image description here

Stefan Müller
  • 6,901
  • 3
  • 29
  • 61
  • 1
    What do you mean with "none of these solutions works in texlive 2014 and 2015."? Does the attached image represent the desired output? If that's so, then in my TeX Live2015 system there's no problem and I get a similar result. – Gonzalo Medina Sep 07 '15 at 15:14
  • I am using xetex. With xetex the arrows are either on top of the figure (above V). I will add the figure. – Stefan Müller Sep 08 '15 at 12:30
  • Just noticed that I might get away with using pdftext and producing a pdf that I then can include with includegramhpics. – Stefan Müller Sep 08 '15 at 12:32
  • LuaLaTeX also works fine. – cfr Sep 08 '15 at 20:56

2 Answers2

2

The source of the problem seems to be PGF's deferred node positioning (PGF manual 102.2.3) using \pgfpositionnodelater and \pgfpositionnodenow, as shown by the example below. (Forest uses deferred node positioning for placing all nodes!)

Run the example using pdflatex and xelatex. In the example, two nodes (A and B) are created in a deferred fashion within the same picture. pgfpositionnodenow positions them at different points, however. The example is set up so that it is clear that PdfLaTeX yields the correct result (0,0) for node A in the lower left corner of tha page. XeLaTeX incorrectly yields the same result for both nodes (I guess because \pgfpositionnodenow is used at the same current point, but I can't figure out the meaning of the resulting dimensions).

I hope someone can shed some light on how to resolve this problem. I'm afraid I'm no good at such low level stuff.

\documentclass{article}
\usepackage[margin=0pt]{geometry}
\parindent 0pt
\usepackage{tikz}
\usepackage{etoolbox}
\newbox\alaterbox
\newbox\blaterbox
\def\asavelaternode{%
  \global\setbox\alaterbox=\box\pgfpositionnodelaterbox
  \global\let\alatername\pgfpositionnodelatername
  \global\let\alaterminx\pgfpositionnodelaterminx
  \global\let\alaterminy\pgfpositionnodelaterminy
  \global\let\alatermaxx\pgfpositionnodelatermaxx
  \global\let\alatermaxy\pgfpositionnodelatermaxy
}
\def\bsavelaternode{%
  \global\setbox\blaterbox=\box\pgfpositionnodelaterbox
  \global\let\blatername\pgfpositionnodelatername
  \global\let\blaterminx\pgfpositionnodelaterminx
  \global\let\blaterminy\pgfpositionnodelaterminy
  \global\let\blatermaxx\pgfpositionnodelatermaxx
  \global\let\blatermaxy\pgfpositionnodelatermaxy
}
\def\arestorelaternode{%
  \setbox\pgfpositionnodelaterbox=\box\alaterbox
  \let\pgfpositionnodelatername\alatername
  \let\pgfpositionnodelaterminx\alaterminx
  \let\pgfpositionnodelaterminy\alaterminy
  \let\pgfpositionnodelatermaxx\alatermaxx
  \let\pgfpositionnodelatermaxy\alatermaxy
}
\def\brestorelaternode{%
  \setbox\pgfpositionnodelaterbox=\box\blaterbox
  \let\pgfpositionnodelatername\blatername
  \let\pgfpositionnodelaterminx\blaterminx
  \let\pgfpositionnodelaterminy\blaterminy
  \let\pgfpositionnodelatermaxx\blatermaxx
  \let\pgfpositionnodelatermaxy\blatermaxy
}
\gdef\pgfsyspdfmark#1#2#3{\csgdef{#1}{(#2 sp, #3 sp)}}
\begin{document}
\makeatletter
\tikzset{every node/.style={inner sep=0, outer sep=0, anchor=north west}}%
\tikz{%
  \pgfpositionnodelater{\asavelaternode}\node(a){\pgfsys@markposition{posa}A};
  \pgfpositionnodelater{\bsavelaternode}\node(b){\pgfsys@markposition{posb}B};
}%
\vfill
A: \csuse{posa}

B: \csuse{posb}

\tikz{%
  \arestorelaternode\pgfpositionnodenow{\pgfqpoint{1cm}{2cm}}%  
  \brestorelaternode\pgfpositionnodenow{\pgfqpoint{5cm}{4cm}}%
}%
\end{document}

PdfLaTeX result:

A: (0 sp, 0 sp)
B: (7458720 sp, 3729360 sp)

XeLaTeX result:

A: (-1864679 sp, -3281531 sp)
B: (-1864679 sp, -3281531 sp)
  • 1
    As I understand it (which isn't much), the problem here is not actually specific to forest at all. Is that right? Because, if so, I suggest asking this as a new question because I think it will get a lot more attention that way. A lot more people will read a generic TikZ/XeTeX question than will read one about forest, especially since this one now appears to have been answered by the author of the package ;). – cfr Sep 09 '15 at 21:31
  • I do not understand how this answer can be a solution. At least it is not a solution for me. – Stefan Müller Jul 02 '23 at 10:44
1

It is possible to point to a particular letter in a string if you pre-compute the offset. I should mention that it is dependent on whatever forest used for [inner sep].

\documentclass{article}
\usepackage{forest}

\usetikzlibrary{calc}
\newlength{\offset}

\begin{document}

\settowidth{\offset}{V[1,2}

\begin{forest}
[V
[AP,name=ap1
[ungewaschen]]
[V{[1,2]},name=arg1]
[isst]]]
tikz={\draw[->, bend angle=40, bend left] (ap1.north) to ($(arg1.north west)+(\offset,0)$);}
\end{forest}

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120