TikZposter 不适用于 pgfplots

TikZposter 不适用于 pgfplots

我无法在中使用轴环境tikzposter,当我添加时\usepackage{pgfplots},我会得到:

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.

以下是一个例子:

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

怎么了?

答案1

@ percusse 是对的:

\pgfdeclarelayer{backgroundlayer}在正确的位置添加即可。

PGF 要求您先定义任何层,然后才能使用它。

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

答案2

问题是 tikzposter 类使用(当然)tikz 包。因此,如果您使用 pgfplots,它会在 tikz 之后加载,从而以某种方式弄乱图层(根据此主题)。我的解决方案是编辑 tikzposter.cls 文件并将 更改为\usepackage{tikz}\usepackage{pgfplots}由于 pgfplots 也加载 tikz,所以这对我来说很管用。

相关内容