# TikZ with “remember picture” compiled with pdflatex yields different results compared to dvips -> ps2pdf

The following document

\documentclass[11pt,a4paper]{report}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[remember picture]
\node [draw] (a) {%
\begin{tabular}{l}
line 1 \\
line 2
\begin{tikzpicture}[remember picture]
\coordinate (line2);
\end{tikzpicture}
\\
line 3 \\
line 4 \\
\end{tabular}
};

\node [draw, right=5cm of line2] (a) {a};

\draw (line2) -- (a);
\end{tikzpicture}
\end{document}


yields a different result when I compile it to PDF using pdflatex compared to using dvips and then ps2pdf.

For instance, here is the (expected) figure produced by pdflatex:

And here is the (incorrect) figure produced by dvips and ps2pdf:

Why is this, and how do I fix it so that the result is always like the one produced by pdflatex?

-
Imho it is a bug in tikz. The dvips-route has problems when the paper size is not a4. See also this discussion (in german) mrunix.de/forums/showthread.php?t=73803. – Ulrike Fischer Aug 20 '12 at 10:47
But I'm using A4 format, and there is no difference if I pick some other format. – gablin Aug 21 '12 at 7:07
No you are not. The default paper format of the article class is letter. It could be that your pdf has another format as you are not using one of the packages which will ensure that the pdf paper size and the latex paper size are the same (article is too old and doesn't do it). Add e.g. \usepackage[a4paper]{geometry}, or load the graphicx package. – Ulrike Fischer Aug 21 '12 at 8:13
I've changed the document class to be the same as in mine original document. Still the same results, and I've tried loading the geometry package as well with a4paper as option. But is there anything I can do to make this work with dvips-ps2pdf? – gablin Aug 21 '12 at 10:44
@gablin Why do you want to go the detour over dvi and postscript? – mrf Aug 21 '12 at 10:54

It's a TikZ/pgf bug with remember picture via latex-dvips-ps2pdf...

In this particular case, the matrix library offers an elegant workaround (working via pdflatex and via latex-dvips-ps2pdf):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[remember picture]
\matrix [draw,matrix of nodes] (m){
line 1 \\ % node m-1-1
line 2 \\ % node m-2-1
line 3 \\
line 4 \\
};
\node [draw, right=5cm of m-2-1] (a) {a};
\draw (m-2-1) -- (a);
\end{tikzpicture}
\end{document}


-
Funnily, this is exactly how I solved it! ^^ – gablin Aug 31 '12 at 12:05