为什么在 tikz 之后加载 pgfplots 会破坏 tikzpicture 中的默认图层?

为什么在 tikz 之后加载 pgfplots 会破坏 tikzpicture 中的默认图层?

杰克的回答针对这个问题宽度相等但高度“合适”的背景矩形pgfplots,我在加载软件包之后出错tikz,但在加载之前没有出错。我假设这是由pgfplots重新定义标准tikz层(参见tikz manual第 4.26 节)引起的,但我不太明白这是否是故意的,以及加载pgfplots之前是否会对其层的预期工作tikz方式产生任何影响。pgfplots

所讨论的错误是:

! Package pgf Error: Sorry, the requested layer 'background' is not part of the 
layer list. Please verify that you provided \pgfsetlayers and that 'background' 
is part of this list.

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.49     \begin{pgfonlayer}{background}

梅威瑟:

\documentclass{article}

\usepackage{pgfplots} % Works fine
\usepackage{tikz}
\usetikzlibrary{backgrounds,fit,calc}
%\usepackage{pgfplots} % Throws an error

\begin{document}

\tikzset{
    schritt/.style={
        draw,
        rounded corners,
        fill=blue!20,
        inner xsep=2em,
    },
    background/.style={
        draw,
        fill=yellow!30,
        align=right
    }
}

% Returns three nodes: The argument, and the projections of the argument on the left and right borders of the bounding box
\newcommand{\extendnode}[1]{
    (#1)
    ($(current bounding box.north east)!(#1)!(current bounding box.south east)$)
    ($(current bounding box.north west)!(#1)!(current bounding box.south west)$)
}

\begin{tikzpicture}
\matrix (matrix) [row sep=0.5cm,column sep=0.5cm] {
  \node (elicit) [schritt] {Wissenserhebung}; & \\
  \node (interpret) [schritt] {Interpretation}; & \\
  & \node (model) [schritt] {Modellierung}; \\
  \node (representation) [schritt] {Repräsentation}; & \\
  \node (integration) [schritt] {Integration}; & \\
  \node (maintenance) [schritt] {Wartung}; & \\
};

\path[->]
  (elicit) edge (interpret)
  (interpret) edge node[right] {\hspace{.35cm}\tiny Modellbasierter Ansatz} (model)
  (interpret) edge node[right] {\tiny Rapid Prototyping} (representation)
  (model) edge (representation)
  (representation) edge (integration)
  (integration) edge (maintenance);

\begin{pgfonlayer}{background}

  \path [use as bounding box] (current bounding box.north west) (current bounding box.south east); % Freeze current bounding box
  \node [fit={\extendnode{elicit}}, background] {First};
  \node [fit={\extendnode{interpret} (model)}, background] {Second};
  \node [fit=\extendnode{representation}, background] {Third};
  \node [fit=\extendnode{integration}, background] {Fourth};
  \node [fit=\extendnode{maintenance}, background] {Fifth};

\end{pgfonlayer}
\end{tikzpicture}


\end{document}

答案1

Pgfplots 不能干扰 TikZ 的层。

唯一允许的关系是如果 TikZ 图片包含 pgfplots 元素(一个轴):在这种情况下,轴应该合并到 TikZ 的图层中(当且仅当已为该图像手动且明确地启用了分层图形)。

您遇到的是一个错误;可能是在您的 pgfplots 版本中。

我知道版本 1.7 修复了 pgfplots 1.6.1 中引入的一些“兼容性回归”,如果使用版本 2.10(当前稳定版本)的 pgf,则会出现此问题。

升级到 pgfplots 1.7(或 1.8)应该会有所帮助。请注意,pgfplots 1.8 应该会在未来几天内在 CTAN 上可用,并且已经在http://sourceforge.net/projects/pgfplots/,因此升级到该版本可能比升级到 1.7 更简单。但 1.7 版本可以完成任务。

相关内容