与 PDFLaTeX 相比,在 XeLaTeX 中编译时 Tikz 偏移原点

与 PDFLaTeX 相比,在 XeLaTeX 中编译时 Tikz 偏移原点

在下面给出的代码中,如果我使用 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}

结果和楼主的第二次拍摄一样

相关内容