从其他文档编译独立的 tikz 图片不起作用

从其他文档编译独立的 tikz 图片不起作用

我有一张 tikz 图片,当我调用时它可以正常工作pdflatex picture.tex

图片.tex

但是,如果我调用pdflatex main.tex使用picture.tex,我会收到以下错误:

! Package pgfkeys Error: I do not know the key '/tikz/spath/save', to which you
 passed 'red_arrow', and I am going to ignore it. Perhaps you misspelled it.

代码picture.tex

% !TeX root = ../../main.tex
% File-name: picture.tex
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{
  spath3,
  intersections
}

\tikzset{
    arrow/.style={
        ->,
        >=late.x
    },
    bridging path/.initial=arc,
    bridging span/.initial=8pt,
    bridging gap/.initial=4pt,
    bridge/.style 2 args={
        spath/split at intersections with={#1}{#2},
        spath/insert gaps after
        components={#1}{\pgfkeysvalueof{/tikz/bridging span}},
        spath/join components upright
        with={#1}{\pgfkeysvalueof{/tikz/bridging path}},
        spath/split at intersections with={#2}{#1},
        spath/insert gaps after
        components={#2}{\pgfkeysvalueof{/tikz/bridging gap}},
    }
}

\begin{document}
\begin{tikzpicture}[node distance=2cm]
    \draw[step=1cm, color=black, opacity=0.7] (0, 0) grid (3, 3);

    \node at (0.5, 0.5) {$s_0$};
    \node at (1.5, 1.5) {$s_x$};
    \node at (0.5, 1.5) {$s_y$};
    \node at (2.5, 2.5) {$g$};

    \path[spath/save=red_arrow] (0.3, 0.7) -- (0.3, 1.7) -- (1.5, 1.7) -- (1.5, 2.4) -- (2.3, 2.4);
    \path[spath/save=blue_arrow] (0.7, 0.7) -- (0.7, 1.5) -- (2.5, 1.5) -- (2.5, 2.3);
    \path[spath/save=green_arrow] (0.7, 0.5) -- (1.5, 0.5) -- (1.5, 1.2) -- (0.5, 1.2) -- (0.5, 2.6) -- (2.3, 2.6);

    \tikzset{bridge={green_arrow}{red_arrow}}
    \tikzset{bridge={blue_arrow}{green_arrow}}

    \draw [arrow, color=red, spath/use=red_arrow];    
    \draw [arrow, color=blue, spath/use=blue_arrow]; 
    \draw [arrow, color=green, spath/use=green_arrow]; 
\end{tikzpicture}
\end{document}

main.tex代码:

\begin{figure}[hb!t]
    \centering
    \includestandalone[width=\linewidth]{figures/picture}
    \caption{description}
    \label{fig:figure}
\end{figure}

我知道我的 tikz 库有问题,但我不知道是什么问题。我已将 TexLive 更新到 2023 版本,但问题仍未解决。

$ pdflatex --version
pdfTeX 3.141592653-2.6-1.40.25 (TeX Live 2023)
kpathsea version 6.3.5
Copyright 2023 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.39; using libpng 1.6.39
Compiled with zlib 1.2.13; using zlib 1.2.13
Compiled with xpdf version 4.04

解决方案

对于那些遇到同样问题的人,使用\usepackage[subpreambles=true]{standalone}解决了问题。mode=build使用 overleaf 时也有所帮助,但它在本地不起作用。我还将移到了里面,\tikzset这样tikzpicture它就不会出现在序言中了。感谢@Qrrbrbirlbel 提供的解决方案。

相关内容