在 Tik Z 和 PGF 手册 2.10-CVS 版本第 120/880 页中,有一个创建黄色圆角矩形背景的示例,如下所示:
下面是我使用的代码:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[execute at end picture=%
{
\begin{pgfonlayer}{background}
\path[fill=yellow,rounded corners]
(current bounding box.south west) rectangle
(current bounding box.north east);
\end{pgfonlayer}
}]
\node at (0,0) {X};
\node at (2,1) {Y};
\end{tikzpicture}
\end{document}
但是我收到如下错误: !包 pgf 错误:抱歉,找不到请求的图层“背景”。也许你拼错了?。
您知道如何解决这个问题吗?提前感谢您的支持。
答案1
在手册中你必须使用\usetikzlibrary{backgrounds}
。它用灰色书写:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[execute at end picture=%
{
\begin{pgfonlayer}{background}
\path[fill=yellow,rounded corners]
(current bounding box.south west) rectangle
(current bounding box.north east);
\end{pgfonlayer}
}]
\node at (0,0) {X};
\node at (2,1) {Y};
\end{tikzpicture}
\end{document}
下面是输出: