# Why the following doesn't render well (clash with tikz and forest?)

The following doesn't render well with tikz and forest used together:

\documentclass[border=10pt]{standalone}
\usepackage[linguistics]{forest}
\usepackage{tikz}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing,quotes}
\tikzstyle{every picture}+=[remember picture,inner xsep=0,inner ysep=0.25ex]

\begin{document}
\Forest{[A[a][B, calign with current [A, calign with current][a]]]}
\end{document}


To see the bad effect, you have to run pdflatex twice on the .tex file. The first time, the pdf renders well, the second time, the branches are separated from the text.

This is related to How do I make a straight skeleton with qtree?

• What's the purpose of remember picture for every picture? – egreg Apr 12 '18 at 13:06
• Forest uses TikZ. You're applying remember to every forest, which won't work. Generally, better apply remember just to the pictures you need it for as it causes all kinds of complications (and excludes externalising with the external library). – cfr Apr 14 '18 at 3:02

I completely agree with the comment from @egreg. The clash of forest with tikz is really in the remember picture.

That being said I would like to propose a working solution, in this case using tikzmark assuming you do want to connect individual figures, while removing remember picture from the tikzstyle. The result is as such:

Notice the arrow created by incorporating the \subnode{ } commands and adding an overlay tikzpicture according to:

\documentclass[border=10pt]{standalone}

\usepackage{forest}
\usetikzlibrary{automata,positioning,decorations.text,topaths,arrows.meta,decorations.pathmorphing,quotes}
\usetikzlibrary{tikzmark}
\tikzstyle{every picture}+=[inner xsep=0,inner ysep=0.25ex]

\begin{document}

\begin{forest}
[A[a][B, calign with current [{A}, calign with current][\subnode{argA1}{a}]]]
\end{forest}

\begin{forest}
[A[\subnode{argB2}{a}][{B}, calign with current [A, calign with current][a]]]
\end{forest}

\begin{tikzpicture}[overlay,remember picture]
\draw[-latex, bend angle=40, bend right] (argA1.north) to (argB2.south);
\end{tikzpicture}

\end{document}

• thanks. I have another place with a tikzpicture where if I don't have the tikzstyle in general with "remember picture", then it doesn't work (even when I add remember picture to that specific tikzpicture). Any ideas why? (though your solution works for the forest picture.) – user2299502 Apr 12 '18 at 14:22
• I fixed that! I didn't put "remember picture" in all places I should have. – user2299502 Apr 12 '18 at 15:04
• That would explain it ;). Great that you found the solution to this minor problem and to the overall one. – Steyn W. Apr 13 '18 at 8:25