与 tikzexternalize 冲突

与 tikzexternalize 冲突

我创建了一些带有对角线的矩阵并对 \vdots 进行了一些调整。(基于这些帖子: 矩阵内的对角线如何使此节点中的 \vdots 垂直居中?

结果正是我想要的,但是当我将代码从测试/试验和错误文件复制到主文件时,我遇到了问题。经过一番搜索,我找到了问题所在:没有 tikzexternal 命令,一切都正常。

然而,我的主文件相当大,所以我不能不用 tikzexternal 命令。

有人能帮我解决这个问题吗?(并解释一下问题是什么?)只需取消注释 3 个 tikzexternalize 行即可重现错误。

(可能相关:启用 tikzexternalize 后,我在每个文档中都会收到不同的错误,如果您需要实际的错误消息,请告诉我)

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

%\usepgfplotslibrary{external} %use with --shell-escape
%\tikzexternalize[prefix=Tikzplots/]
%\pgfplotsset{compat=newest}

\makeatletter               %vdots without extra space on top
\DeclareRobustCommand{\rvdots}{%
    \vbox{
        \baselineskip4\p@\lineskiplimit\z@
        \kern-\p@
        \hbox{.}\hbox{.}\hbox{.}
}}
\makeatother


\newcommand\tikzmark[1]{%       %nodes in matrix for lines
    \tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {};}

\newcommand\MyLine[3][]{%       %draw lines between the nodes^
    \begin{tikzpicture}[overlay,remember picture]
    \draw[#1] (#2.north west) -- (#3.east);
    \end{tikzpicture}}



\begin{document}

\[
\begin{bmatrix}
Y[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
Y[k]
\end{bmatrix}
=
\begin{bmatrix}
\phantom{0}\tikzmark{a} & \phantom{0}& \phantom{0}& \phantom{0}&\phantom{0}& \phantom{0} \\
\\
\\
\\
\\
& & & & & \tikzmark{b}\phantom{0}
\end{bmatrix}
\cdot
\begin{bmatrix}
X[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
X[k]
\end{bmatrix}
\]



\[
\begin{bmatrix}
Y[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
Y[k]
\end{bmatrix}
=
\begin{bmatrix}
\phantom{0}\tikzmark{c} & \phantom{0} &\phantom{0}\tikzmark{e} &\phantom{0} & \phantom{0}\tikzmark{g}& \phantom{0}\\
& & & & &\tikzmark{h}\phantom{0}\\
\phantom{0}\tikzmark{i}& & & & &\\
& & & & & \tikzmark{f}\phantom{0} \\
\phantom{0}\tikzmark{k}& & & & &\\
&\tikzmark{l}\phantom{0} & &\tikzmark{j}\phantom{0} & & \tikzmark{d}\phantom{0}\\
\end{bmatrix}
\cdot
\begin{bmatrix}
X[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
X[k]
\end{bmatrix}
\] 
\MyLine[thick]{a}{b}
\MyLine[red,thick]{c}{d}
\MyLine[thick]{e}{f}
\MyLine[thick]{g}{h}
\MyLine[thick]{i}{j}
\MyLine[thick]{k}{l}
\end{document}

答案1

如果在适当的位置添加\tikzexternaldisabletikzexternalenable(并添加缺少的pgfplots-package),它对我来说很好:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}

\usepgfplotslibrary{external} %use with --shell-escape
\tikzexternalize[prefix=Tikzplots/]
\pgfplotsset{compat=newest}

\makeatletter               %vdots without extra space on top
\DeclareRobustCommand{\rvdots}{%
    \vbox{
        \baselineskip4\p@\lineskiplimit\z@
        \kern-\p@
        \hbox{.}\hbox{.}\hbox{.}
}}
\makeatother


\newcommand\tikzmark[1]{%       %nodes in matrix for lines
    \tikzexternaldisable\tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {};\tikzexternalenable}

\newcommand\MyLine[3][]{%       %draw lines between the nodes^
    \tikzexternaldisable
    \begin{tikzpicture}[overlay,remember picture]
    \draw[#1] (#2.north west) -- (#3.east);
    \end{tikzpicture}\tikzexternalenable}



\begin{document}

\[
\begin{bmatrix}
Y[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
Y[k]
\end{bmatrix}
=
\begin{bmatrix}
\phantom{0}\tikzmark{a} & \phantom{0}& \phantom{0}& \phantom{0}&\phantom{0}& \phantom{0} \\
\\
\\
\\
\\
& & & & & \tikzmark{b}\phantom{0}
\end{bmatrix}
\cdot
\begin{bmatrix}
X[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
X[k]
\end{bmatrix}
\]



\[
\begin{bmatrix}
Y[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
Y[k]
\end{bmatrix}
=
\begin{bmatrix}
\phantom{0}\tikzmark{c} & \phantom{0} &\phantom{0}\tikzmark{e} &\phantom{0} & \phantom{0}\tikzmark{g}& \phantom{0}\\
& & & & &\tikzmark{h}\phantom{0}\\
\phantom{0}\tikzmark{i}& & & & &\\
& & & & & \tikzmark{f}\phantom{0} \\
\phantom{0}\tikzmark{k}& & & & &\\
&\tikzmark{l}\phantom{0} & &\tikzmark{j}\phantom{0} & & \tikzmark{d}\phantom{0}\\
\end{bmatrix}
\cdot
\begin{bmatrix}
X[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
X[k]
\end{bmatrix}
\] 
\MyLine[thick]{a}{b}
\MyLine[red,thick]{c}{d}
\MyLine[thick]{e}{f}
\MyLine[thick]{g}{h}
\MyLine[thick]{i}{j}
\MyLine[thick]{k}{l}
\end{document}

相关内容