[Tex/LaTex] Multiple tikzpictures in a standalone document

standalonetikz-pgf

I have a standalone document of the form:

\documentclass[tikz]{standalone}
%\documentclass{article}
%\usepackage{tikz}

\usetikzlibrary{positioning}

\newcommand{\tikzmark}[2]{\tikz[remember picture, baseline] \node[inner sep=0pt, outer sep=0pt, anchor=base] (#1) {#2};}

\begin{document}

\begin{tikzpicture}[remember picture]
\node (A) {
\begin{tabular}{ll}
1 & \tikzmark{two}{2} \\
3 & 4 \\
\end{tabular}};

\node[right=of A] (B) {
\begin{tabular}{ll}
5 & 6 \\
\tikzmark{seven}{7} & 8 \\
\end{tabular}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\draw[->] (two) -- (seven);
\end{tikzpicture}
\end{document}

The contents are displayed correctly when using the article documentclass instead of standalone.

Can anyone suggest how to make it so that the contents of all tikzpictures are displayed?

Best Answer

Works fine with just one tikzpicture here. You have to compile twice of course.

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}

\newcommand{\tikzmark}[2]{\tikz[remember picture, baseline] \node[inner sep=0pt, outer sep=0pt, anchor=base] (#1) {#2};}

\begin{document}

\begin{tikzpicture}[remember picture]
\node (A) {
\begin{tabular}{ll}
1 & \tikzmark{two}{2} \\
3 & 4 \\
\end{tabular}};

\node[right=of A] (B) {
\begin{tabular}{ll}
5 & 6 \\
\tikzmark{seven}{7} & 8 \\
\end{tabular}};

\draw[->] (two) -- (seven);
\end{tikzpicture}
\end{document}

enter image description here