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.

I'm trying to place an image in the background using TikZ layers but as soon as I enable the layers option, everything in the background layer disappears. I have no idea why. I found some hints about the main layer but this problem seems to be with the background layer. I also tried the backgrounds library. Same problem. (I've had success with layers on this same machine before but I'm no expert.)

\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}
share|improve this question

1 Answer 1

up vote 5 down vote accepted

Use \usetikzlibrary and declare and set the layers before you start the tikzpicture environment. When I did this, the missing nodes and edges appeared.

You could move also \tikzstyle, but here it would be better to use \tikzset instead, or to give the styles as option to the tikzpicture environment.

\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}]
...
share|improve this answer
    
So, simply moving the usetikzlibrary out of the tikzpicture environment solved it. –  recluze Jan 15 '12 at 15:57

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.