2

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: enter image description here

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

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

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
gablin
  • 17,006
  • 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) http://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 07: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 08: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
  • @mrf: Actually, I usually use pdflatex, but in this document the original author used dvips-ps2pdf so I continued with that, seeing no reason to change it. However, my concern is that if I submit a paper with TikZ figures to a conference, and they happen to use the dvips-ps2pdf approach, I want to make sure that the end result at their end looks exactly like I see on my machine. So I want to find out what's the problem here. =) – gablin Aug 21 '12 at 12:57
  • Well, there's always the option to compile TikZ into external files and use \includegraphics... – krlmlr Aug 21 '12 at 13:25
  • @user946850: Not sure that works when the conference requires that the paper consists of a single TeX document. – gablin Aug 21 '12 at 14:06
  • The conference doesn't want figures in their papers? Pardon me? – krlmlr Aug 21 '12 at 14:45
  • @user946850: No, you misunderstood. Conferences do indeed want figures, but sometimes they require that the entire paper consists of a single TeX document. This means the figures must be part of the TeX document and cannot thus be generated as separate files and then included. And if they happen to use the dvips-ps2pdf approach and I use the pdflatex approach when generating my paper, I want there to be no discrepancies between the produced PDFs. – gablin Aug 22 '12 at 07:01
  • No plots? No raster images? – krlmlr Aug 23 '12 at 00:00
  • @user946850: Now that I haven't figured out yet how they would solve it. =) – gablin Aug 28 '12 at 07:21

1 Answers1

4

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}

enter image description here

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283