我正在尝试使用 TikZ 图层将图像放置在背景中,但只要启用图层选项,背景图层中的所有内容就会消失。我不知道为什么。我发现了一些关于主图层的提示,但这个问题似乎出在背景图层上。我也尝试了这个backgrounds
库。同样的问题。(我以前在同一台机器上成功使用过图层,但我不是专家。)
\begin{tikzpicture}
\usetikzlibrary{arrows,positioning,fit}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\tikzstyle{userblock}=[draw,rectangle,fill=gray!15,minimum height=4em,minimum width=4em, node distance=6em];
\tikzstyle{tasklabels}=[node distance=5em];
\tikzstyle{compblock}=[draw=blue, fill=blue!15,node distance=5em, minimum height=4em, minimum width=20em, inner sep=1em];
\node[userblock] (u1) {user$_1$} ;
\node[userblock,right of=u1] (u2) {user$_2$} ;
\node[userblock, draw=none,fill=none,right of=u2] (udots) {\ldots} ;
\node[userblock,right of=udots] (un) {user$_n$} ;
\node[tasklabels,below of=u1] (l1) {compiler}
edge [<->] (u1);
\node[tasklabels, below of=u2] (l2) {assembler}
edge [<->] (u2) ;
\node[tasklabels, below of=udots] (ldots) {...}
;
\node[tasklabels, below of=un] (ln) {database system}
edge [<->] (un) ;
\begin{pgfonlayer}{background}
\node[compblock,fit=(l1)(ln)] (L1) {System and Application Programs}
edge [-,dashed] (l1)
edge [-,dashed] (l2)
edge [-,dashed] (ln) ;
\node[compblock,below of=L1] (L2) {Operating System}
edge [<->] (L1) ;
\node[compblock,below of=L2] (L3) {Computer Hardware}
edge [<->] (L2) ;
\end{pgfonlayer}
\end{tikzpicture}
答案1
在启动环境之前使用\usetikzlibrary
并声明并设置层tikzpicture
。当我这样做时,出现了缺失的节点和边。
您也可以移动\tikzstyle
,但这里最好使用\tikzset
,或者将样式作为tikzpicture
环境选项。
\begin{tikzpicture}[%
userblock/.style={draw,rectangle,fill=gray!15,minimum height=4em,
minimum width=4em, node distance=6em},
tasklabels/.style={node distance=5em]},
compblock/.style={draw=blue, fill=blue!15,node distance=5em,
minimum height=4em, minimum width=20em, inner sep=1em}]
...