Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Taking the MWE from Jake's answer to the question Background rectangles with equal width but 'fitting' height, I get an error when loading pgfplots after the tikz packages but not before. I'm assuming this is caused by pgfplots redefining the standard tikz layers (cf. tikz manual Section 4.26) but I don't quite understand if this is intentional and whether loading pgfplots before tikz has any consequences for how pgfplots expects its layers to work.

The error in question is:

! 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}

MWE:

\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}
share|improve this question
2  
You don't need to load TikZ anyways. It's loaded by pgfplots and Tikz doesn't have any options to change so it's redundant. Just let pgfplots do its magic internally. –  percusse Mar 24 '13 at 1:10
    
@percusse That would solve it, alright, since any \usetikzlibrary will necessarily come after pgfplots is loaded anyway. I'm guessing that means that loading tikz second would not interfere with the layers pgfplots establishes then, as pgfplots presumably takes care of that when loading tikz in its own code. –  ThomasH Mar 24 '13 at 1:41
    
It won't interfere because that statement would be ignored completely since TikZ is already loaded. See for example this one for a bit better explanation tex.stackexchange.com/a/25673/3235 –  percusse Mar 24 '13 at 2:02
1  
your MWE works fine for me- perhaps How do I update my TeX distribution? –  cmhughes Mar 24 '13 at 3:32
add comment

1 Answer 1

Pgfplots must not interfere with layers of TikZ.

The only allowed relation is if a TikZ picture contains a pgfplots element (an axis): in this case, the axis should merge into TikZ's layers (if and only if layered graphics has been enabled manually and explicitly for that image).

What you experience is a bug; probably in your version of pgfplots.

I am aware of the fact the version 1.7 fixed some "compatibility regression" which has been introduced in pgfplots 1.6.1 and which exists if pgf with version 2.10 (the current stable) is used.

An upgrade to pgfplots 1.7 (or 1.8) should help. Note that pgfplots 1.8 should be available on CTAN within the next days and is already available on http://sourceforge.net/projects/pgfplots/, so it might be simpler to upgrade to that version rather than 1.7. But 1.7 does the job.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.