使用 pdflatex 編譯的帶有“記住圖片”的 TikZ 與 dvips -> ps2pdf 相比產生不同的結果

使用 pdflatex 編譯的帶有“記住圖片”的 TikZ 與 dvips -> ps2pdf 相比產生不同的結果

以下文件

\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}

pdflatex與使用dvipsand then相比,當我將其編譯為 PDF 時,會產生不同的結果ps2pdf

例如,這是由 產生的(預期)數字pdflatex在此輸入影像描述

dvips這是由和產生的(不正確的)數字ps2pdf在此輸入影像描述

為什麼會這樣,我該如何解決它,以便結果總是像 產生的結果一樣pdflatex

答案1

這是一個 TikZ/pgf 錯誤,remember picture透過latex-dvips-ps2pdf...

在這種特殊情況下,matrix庫提供了一個優雅的解決方法(通過pdflatex和 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}

在此輸入影像描述

相關內容