TikZ 移動座標在新機器上的表現有所不同

TikZ 移動座標在新機器上的表現有所不同

我開始使用一台新計算機,我之前的 TikZ 程式碼之一產生了意想不到的結果。經過調試,我得到了以下MWE。

\documentclass{article}
\usepackage{tikz}

\begin{document}
\thispagestyle{empty}
    \begin{tikzpicture}[remember picture,overlay]
        \coordinate  (CENTER) at (current page.center);
        \coordinate  (A) at ([xshift=1cm,yshift=-2cm] CENTER); %This coordinate is not shifted on PGF 3.1.5 running on texlive on windows; but it is shifted on PGFs 3.1 running on MacTex.
        \coordinate [xshift=1cm,yshift=-2cm] (B) at (CENTER); %This is shifted in both computers.

        \node at (CENTER) {XXX};
        \node at (A) {000};
        \node at (B) {111};
    \end{tikzpicture}
\end{document}

奇怪的是,當我在新機器(Windows 上全新的vanilla texlive,更新的PGF 版本3.1.5)中編譯此程式碼時,移位並未應用於座標(A),因此它停留在(CENTER)上。然而,在我之前的電腦上(在 MACOS 上運行帶有 PGF 版本 3.1 的 MacTex 2019),坐標 (A) 發生了移動,因此它顯示在 (B) 上方。

此行為會發生在座標上,但不會發生在節點上。在以下程式碼中,節點 (A) 和 (B) 如預期的那樣出現在同一位置。

\begin{tikzpicture}[remember picture,overlay]
    \node  (CENTER) at (current page.center) {XXX};
    \node  (A) at ([xshift=1cm,yshift=-2cm] CENTER) {000};
    \node [xshift=1cm,yshift=-2cm] (B) at (CENTER) {111};
\end{tikzpicture}%

有人知道為什麼會發生這種情況?我應該在某個地方將其報告為錯誤(如何)?我擔心我必須更新所有舊程式碼,才能在新機器上編譯文件。

答案1

這個問題已經在 中得到了不那麼直接的解決第809章。由於這是一個嚴重的問題,修補程式 3.1.5a已經發布,幾天後您就可以從 CTAN 獲取它。

同時,亨利·門克提供了一個解決方法:

\makeatletter
\def\tikz@@coordinate@at@math#1{%
  \pgf@process{#1}%
  \edef\tikz@temp{(\the\pgf@x,\the\pgf@y)}%
  \expandafter\tikz@coordinate@caller\tikz@temp{}%
}%
\makeatother

3.1.5中的工作範例:

\documentclass{article}
\usepackage{tikz}
\makeatletter
\def\tikz@@coordinate@at@math#1{%
  \pgf@process{#1}%
  \edef\tikz@temp{(\the\pgf@x,\the\pgf@y)}%
  \expandafter\tikz@coordinate@caller\tikz@temp{}%
}%
\makeatother
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
  \coordinate (CENTER) at (current page.center);
  \coordinate (A) at ([xshift=1cm,yshift=-2cm] CENTER);
  \coordinate [xshift=1cm,yshift=-2cm] (B) at (CENTER); 
  \node at (CENTER) {XXX};
  \node at (A) {000};
  \node at (B) {111};
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容