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 make a diagram that shows relations of elements in a system, but I don't know how to layer anything.

So far I've got:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}

\begin{document}

\tikzstyle{narrow} = [draw, fill=blue!20, text width=2cm, text centered, minimum height=1cm]
\tikzstyle{wide}   = [draw, fill=orange!20, text width=7.5cm, text centered, minimum height=1.75cm, rounded corners]
\tikzstyle{tall}   = [draw, fill=green!20, text width=1.75cm, text centered, minimum height=7cm, rounded corners]
\tikzstyle{squar} = [draw, fill=yellow!10, text width=4.75cm, text centered, minimum height=3.75cm, rounded corners]

\def\blockdist{5}
\def\edgedist{5}

\begin{tikzpicture}
  \node (lib)     [tall]   {Library};
  \node at (3,-1) (tman)    [narrow] {tmon};
  \node (ksman)   [narrow] [right=.75cm of tman]   {ksmon};
  \node (stsp)    [narrow] [right=.75cm of ksman]  {stosp};
  \node (deamon)  [wide]   [below=.75cm of ksman]  {base};
  \node (imgan)   [narrow] [above=.75cm of tman]   {img-analysis};
  \node (thrman)  [narrow] [above=.75cm of imgan]  {thermal-analysis};
  \node (scrpts)  [squar]  [right=.75cm of thrman] {Scripts};
\end{tikzpicture}

\end{document}

There are three things I'm trying to accomplish:

  1. How can I put a box around/behind the "ksmon" and "stosp" nodes?
  2. How can I put a box around/behind the one created above and the "tmon" node?
  3. How can I put nodes in/on top of the "Scripts" nodes?
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

I don't really know where you had your problems …
If you really want the boxes that go behind tmon, ksmon and stosp to be drawn after the nodes you can use PGF's layers.

Code

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\tikzset{
    narrow/.style={draw, fill=blue!20, text width=2cm, text centered, minimum height=1cm},
    wide/.style={draw, fill=orange!20, text width=7.5cm, text centered, minimum height=1.75cm, rounded corners},
    tall/.style={draw, fill=green!20, text width=1.75cm, text centered, minimum height=7cm, rounded corners},
    squar/.style={draw, fill=yellow!10, text width=4.75cm, text centered, minimum height=3.75cm, rounded corners}
}

\def\blockdist{5}
\def\edgedist{5}
\begin{document}
\begin{tikzpicture}
  \node (lib)     [tall]   {Library};
  \node at (3,-1) (tman)    [narrow] {tmon};
  \node (ksman)   [narrow] [right=.75cm of tman]   {ksmon};
  \node (stsp)    [narrow] [right=.75cm of ksman]  {stosp};
  \node (deamon)  [wide]   [below=.75cm of ksman]  {base};
  \node (imgan)   [narrow] [above=.75cm of tman]   {img-analysis};
  \node (thrman)  [narrow] [above=.75cm of imgan]  {thermal-analysis};
  \node (scrpts)  [squar]  [right=.75cm of thrman] {Scripts};
  \begin{pgfonlayer}{background}
    \fill[red!25] ([shift={(-.35,.35)}]tman.north west) rectangle ([shift={(.35,-.35)}]stsp.south east);
    \fill[red!50] ([shift={(-.25,.25)}]ksman.north west) rectangle ([shift={(.25,-.25)}]stsp.south east);
  \end{pgfonlayer}
  \node[fill=blue!30,above=.4cm of scrpts.center] (scriptsnode) {Hello, I am a node!};
\end{tikzpicture}
\end{document}

Output

enter image description here


Maybe you're aiming for a more automatic way; you can use the fit library (\usetikzlibrary{fit}) for that and instead of the rectangles you now can do:

  \begin{pgfonlayer}{background}
     \node [fill=red!50, inner sep=.35cm, fit=(tman)(stsp)] {};
     \node [fill=red!25, inner sep=.25cm, fit=(ksman)(stsp)] {};
%    \fill[red!25] ([shift={(-.35,.35)}]tman.north west) rectangle ([shift={(.35,-.35)}]stsp.south east);
%    \fill[red!50] ([shift={(-.25,.25)}]ksman.north west) rectangle ([shift={(.25,-.25)}]stsp.south east);
  \end{pgfonlayer}
share|improve this answer
    
Thanks. I started having problems when I didn't know how to do layers. (echo ... echo ...) :) –  Jamie Nov 16 '12 at 1:31
add comment

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.