[Tex/LaTex] TikZposter does not work with pgfplots

pgfplotstikzposter

I can't use axis environment in tikzposter, when I add \usepackage{pgfplots}, I will get:

Package pgf Error: Sorry, the requested layer 'backgroundlayer' is not part o
f the layer list. Please verify that you provided \pgfsetlayers and that 'backg
roundlayer' is part of this list.

Here's an example:

\documentclass[landscape,a0paper, margin=9mm, innermargin=9mm,
 blockverticalspace=14mm, colspace=12mm, subcolspace=0.1mm]{tikzposter}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{block}
\begin{tikzfigure}
\begin{tikzpicture}[>=latex]
\begin{pgfonlayer}{backgroundlayer}
\begin{axis}[%
width=\figurewidth,
height=\figureheight,
at={(0.803629in,0.513333in)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=25,
xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25},
xticklabels={{},{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{}},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=1300,
ymax=2000,
ytick={1300, 1800, 1900, 2000},
ymajorgrids
]
\addplot [color=red,solid,line width=4.0pt,mark size=10.0pt,mark=*,mark options={solid,fill=red},forget plot]
  table[row sep=crcr]{%
1   1912\\
2   1895\\
3   1916\\
...
24  1878\\
};
\end{axis}
  \end{pgfonlayer}
\end{tikzpicture}
\end{tikzfigure}
}
\end{document}

What's wrong?

Best Answer

@ percusse is right:

Adding \pgfdeclarelayer{backgroundlayer} in the correct place works.

PGF requires you to define any layer before you can use it.

\documentclass[landscape,a0paper, margin=9mm, innermargin=9mm,
 blockverticalspace=14mm, colspace=12mm, subcolspace=0.1mm]{tikzposter}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{block}{Title}{Text}
\begin{tikzpicture}[>=latex]
\pgfdeclarelayer{backgroundlayer}
\begin{pgfonlayer}{backgroundlayer}
\begin{axis}[%
width=20cm,height=20cm,
at={(0.803629in,0.513333in)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=25,
xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25},
xticklabels={{},{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{}},
xmajorgrids,
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=1300,
ymax=2000,
ytick={1300, 1800, 1900, 2000},
ymajorgrids
]
\addplot [color=red,solid,line width=4.0pt,mark size=10.0pt,mark=*,mark options={solid,fill=red},forget plot]
  table[row sep=crcr]{%
1   1912\\
2   1895\\
3   1916\\
24  1878\\
};
\end{axis}
  \end{pgfonlayer}
\end{tikzpicture}
\end{block}

\end{document}
Related Question