與 PDFLaTeX 相比,Tikz 在 XeLaTeX 中編譯時偏移原點

與 PDFLaTeX 相比,Tikz 在 XeLaTeX 中編譯時偏移原點

在下面給出的程式碼中,如果我使用 WinEdt 和 XeLaTeX 進行編譯,我的方程式如下:

在此輸入影像描述

然而,當我使用 PFDLaTeX 編譯時,方程式正確輸出:

在此輸入影像描述

如何使用 XeLaTeX 正確顯示方程式?

這是代碼:

\documentclass{book}

\usepackage{amsmath,amsfonts,amssymb,amsthm, bm}
\usepackage{tikz}

\usetikzlibrary{tikzmark,calc,arrows,shapes,fit,decorations.pathreplacing,pgfplots.groupplots, matrix}
\tikzset{every picture/.style={remember picture}}

\begin{document}

\begin{equation}
\tikz{\node{\subnode{d4}{$\hat{{\theta}}_{BLU}(k+1)$} = \subnode{d5}{$\hat{{\theta}}_{BLU}(k)$} + \subnode{d6} {$\mathbf{K_{B}}(k+1)$}\subnode{d7}{$\big(\underbrace{z(k+1)-\mathbf{h}'(k+1)\hat{{\theta}}_{BLU}(k)}\big)$}};}
\end{equation}

\begin{tikzpicture}[remember picture,overlay]
\draw[blue,thick,->] (d4) to [in=90,out=245] + (245:2.2cm) node[anchor=north,text = black] {current estimate};
\draw[blue,thick,->] (d5) to [in=90,out=265] +(255:1.1cm) node[anchor=north,text = black] {previous estimate};
\draw[blue,thick,->] (d6) to [in=90,out=265] +(279:2.0cm) node[anchor=north,text = black,text width=3cm,align=center]
 {(gain)\\ The weight\\ of the adjustment};
\draw[blue,thick,->] (d7) to [in=90,out=265] +(335:1.6cm) node[anchor=north,text = black,text width=4cm,align=center]
 {residual prediction\\ how far the previous\\ estimation from the \\ current measurement};
\end{tikzpicture}

\end{document}

答案1

我不太明白你的方法,但我會這樣做。它與 xelatex 和 pdflatex 一起使用。

重點是定義一個巨集

\tikznode[..options..]{..label..}{..contents..}

標記箭頭來源的內容。若要新增箭頭和文本,請使用

\begin{tikzpicture}[remember picture,overlay]
  ... tikz code using the labels defined by \tikznode ...
\end{tikzpicture}

\tikznode將前言中的命令定義為

\usepackage{tikz}
\newcommand\tikznode[3][]%
   {\tikz[remember picture,baseline=(#2.base)]
      \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
   }

在此輸入影像描述

\documentclass{book}
\usepackage{tikz}
\newcommand\tikznode[3][]%
   {\tikz[remember picture,baseline=(#2.base)]
      \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
   }
\begin{document}

\begin{equation}
\tikznode{d4}{$\hat{{\theta}}_{BLU}(k+1)$} = \tikznode{d5}{$\hat{{\theta}}_{BLU}(k)$}
+ \tikznode{d6}{$\mathbf{K_{B}}(k+1)$}\tikznode{d7}{$\big(\underbrace{z(k+1)-\mathbf{h}'(k+1)\hat{{\theta}}_{BLU}(k)}\big)$}
\end{equation}

\begin{tikzpicture}[remember picture,overlay]
\draw[blue,thick,->] (d4) to [in=90,out=245] + (245:2.2cm) node[anchor=north,text = black] {current estimate};
\draw[blue,thick,->] (d5) to [in=90,out=265] +(255:1.1cm) node[anchor=north,text = black] {previous estimate};
\draw[blue,thick,->] (d6) to [in=90,out=265] +(279:2.0cm) node[anchor=north,text = black,text width=3cm,align=center]
 {(gain)\\ The weight\\ of the adjustment};
\draw[blue,thick,->] (d7) to [in=90,out=265] +(335:1.6cm) node[anchor=north,text = black,text width=4cm,align=center]
 {residual prediction\\ how far the previous\\ estimation from the \\ current measurement};
\end{tikzpicture}

\end{document}

答案2

對於@gernot:這是同一個問題,因為解決方案適用

\documentclass{book}

\usepackage{amsmath,amsfonts,amssymb,amsthm, bm}
\usepackage{tikz}

\usetikzlibrary{tikzmark,calc,arrows,shapes,fit,decorations.pathreplacing,pgfplots.groupplots, matrix}
\tikzset{every picture/.style={remember picture}}

\begin{document}

\makeatletter
\def\pgfsys@hboxsynced#1{%
  {%
    \pgfsys@beginscope%
    \setbox\pgf@hbox=\hbox{%
      \hskip\pgf@pt@x%
      \raise\pgf@pt@y\hbox{%
        \pgf@pt@x=0pt%
        \pgf@pt@y=0pt%
        \special{pdf: content q}%
        \pgflowlevelsynccm% 
        \pgfsys@invoke{q -1 0 0 -1 0 0 cm}%
        \special{pdf: content -1 0 0 -1 0 0 cm q}% translate to original coordinate system
        \pgfsys@invoke{0 J [] 0 d}% reset line cap and dash
        \wd#1=0pt%
        \ht#1=0pt%
        \dp#1=0pt%
        \box#1%
        \pgfsys@invoke{n Q Q Q}%
      }%
      \hss%
    }%
    \wd\pgf@hbox=0pt%
    \ht\pgf@hbox=0pt%
    \dp\pgf@hbox=0pt%
    \pgfsys@hbox\pgf@hbox%
    \pgfsys@endscope%
  }%
}
\makeatother


\begin{equation}
\tikz{\node{\subnode{d4}{$\hat{{\theta}}_{BLU}(k+1)$} = \subnode{d5}{$\hat{{\theta}}_{BLU}(k)$} + \subnode{d6} {$\mathbf{K_{B}}(k+1)$}\subnode{d7}{$\big(\underbrace{z(k+1)-\mathbf{h}'(k+1)\hat{{\theta}}_{BLU}(k)}\big)$}};}
\end{equation}

\begin{tikzpicture}[remember picture,overlay]
\draw[blue,thick,->] (d4) to [in=90,out=245] + (245:2.2cm) node[anchor=north,text = black] {current estimate};
\draw[blue,thick,->] (d5) to [in=90,out=265] +(255:1.1cm) node[anchor=north,text = black] {previous estimate};
\draw[blue,thick,->] (d6) to [in=90,out=265] +(279:2.0cm) node[anchor=north,text = black,text width=3cm,align=center]
 {(gain)\\ The weight\\ of the adjustment};
\draw[blue,thick,->] (d7) to [in=90,out=265] +(335:1.6cm) node[anchor=north,text = black,text width=4cm,align=center]
 {residual prediction\\ how far the previous\\ estimation from the \\ current measurement};
\end{tikzpicture}

\end{document}

結果與OP的第二個快照相同

相關內容