2

I am trying to get this figure:

enter image description here

The figure is generated by the following code:

\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{fit,shapes,backgrounds,arrows}

\begin{document} 

\begin{tikzpicture}
\tikzstyle{bigbox} = [minimum width=3.5cm, minimum height=4.2cm,draw, thick, rounded corners, rectangle]
\tikzstyle{bigbox2} = [minimum width=2cm, draw, thick, rounded corners, rectangle]
\tikzstyle{box} = [minimum width=2.7cm, rounded corners,rectangle]

\begin{scope}[every node/.style={minimum width=2cm,minimum height=1.5cm,draw,inner sep=0pt}]
 \node [txtstyle] (n1) {};
 \node [txtstyle,xshift=2cm] (n2) {};   
 \node [txtstyle,xshift= 4cm] (n3) {}; 
\end{scope}

\begin{scope}[every node/.style={text width=2cm,anchor=north west,text height=2.86cm,draw}]
\node [txtstyle,xshift=4.985cm,yshift=0.76cm] (n4) {};

\end{scope}
\begin{scope}[every node/.style={text width=5.77cm,anchor=north west,text height=0.3cm,text centered}]
\node [txtstyle,xshift=-1.01cm,yshift=-0.733cm,draw] (n5) {}; %
\node [txtstyle,xshift=-1.01cm,yshift=-1.27cm,draw] (n6) {}; %
\node [txtstyle,xshift=-1.01cm,yshift=-1.8cm,draw] (n7) {}; %
     \node  at (n5.north west){Query Compiler};
     \node  at (n6.north west){Query Optimizer};
     \node  at (n7.north west){Query Executor};

\end{scope}

\begin{scope}[every node/.style={text width=2cm,anchor=north west,text centered}]
     \node  at (n1.north west){Command \\ Line \\ Interface}; 
     \node  at (n2.north west){Web \\ Interface};  
     \node  at (n3.north west){JDBC/ \\ ODBC \\ Server};
     \node  at (n4.north west){ ~\\ ~\\  ~\\ Meta \\ Data \\~ \\};
\end{scope}

\begin{pgfonlayer}{background}
  \node[bigbox] [fit = (n1) (n4)] (box) {};
\end{pgfonlayer}

\node[box,above of=n1,xshift=0.5cm] (us) {Upper System Level};
%
%
%
\begin{scope}[every node/.style={minimum width=2cm,minimum height=0.5cm,rounded corners,inner sep=0pt}]
  \node [txtstyle,below of=box,yshift=-2.5cm,draw] (h1) {Master};
  \node [txtstyle,below left of=h1,yshift=-0.5cm,xshift=-2.3cm,draw] (h2) {Slave};
  \node [txtstyle,below  of=h1,yshift=-0.3cm] (h3) {...};
  \node [txtstyle,below right of=h1,yshift=-0.5cm,xshift=2.3cm,draw] (h4) {Slave};
  \node [txtstyle,above of=h2,yshift=0.3cm] (hd) {Hadooop};
\end{scope}

\begin{pgfonlayer}{background}
  \node[bigbox2] [fit = (hd) (h4)] (box2) {};

 \draw[<->,>=latex', shorten >=2pt, shorten <=2pt,thick] (h1.200) to (h2.north);
 \draw[<->,>=latex', shorten >=2pt, shorten <=2pt,thick] (h1.340) to (h4.north);
   \draw[
        -triangle 90,
        line width=1.5mm,
        postaction={draw, line width=0.4cm, shorten >=0.2cm, -}
    ] (box.south) -- (box2.north);
\end{pgfonlayer}

\end{tikzpicture}
\end{document}

This is a combination of a bunch of code I found on this site. It generates what I want, except that it complains about the \tikzstyle command, indicating that it doesn't know what it is and that it will ignore it (yet it generates what I want when I force it to complete compilation). The code seems quite crude and inelegant. In my quest to learn tikz better, I thought I would ask the experts on this forum if there is a cleaner way of achieving what I wish.

Peter Grill
  • 223,288
ozsu
  • 2,385

2 Answers2

3

I managed to find a slightly more elegant solution using split rectangles and alignment. This at least removes some of the finagling with the placement of individual boxes. Perhaps this is useful.

  \documentclass[10pt]{article}
  \usepackage{tikz}
  \usetikzlibrary{fit,shapes,backgrounds,arrows}

  \begin{document} 

  \begin{tikzpicture}
  \tikzstyle{bigbox} = [minimum width=3.5cm, minimum height=4.2cm,draw, thick, rounded corners, rectangle]
  \tikzstyle{bigbox2} = [minimum width=2cm, draw, thick, rounded corners, rectangle]
  \tikzstyle{box} = [minimum width=2.7cm, rounded corners,rectangle]
  \tikzstyle{vbox} = [minimum width=2.7cm,rectangle,inner sep = -0.8pt]
  \tikzset{txtstyle/.style={text=black}}

 \node[align=center,draw,shape=rectangle split,
      rectangle split horizontal,
      rectangle split parts=3, text width=2cm,text centered] (A)
       {Command \\ Line \\ Interface\nodepart{two}Web \\ Interface\nodepart{three}JDBC/ \\ ODBC \\ Server};

 \node [align=center,draw,shape=rectangle split,
   rectangle split parts=3, text width=6.5cm,text centered,anchor=north] (B) at (A.south) 
    {Query Compiler\nodepart{two}Query Optimizer\nodepart{three}Query Executor};

 \node[vbox][fit=(A) (B)] (virtual) {};
 \node[align=center,shape=rectangle,draw,text width=1.5cm,text height=0.68cm,anchor=west] (C) at (virtual.east) { ~\\ ~\\ Meta \\ Data \\~ \\~ \\};

  \begin{pgfonlayer}{background}
    \node[bigbox] [fit = (virtual) (C)] (box) {};
  \end{pgfonlayer}

  \node[box,above of=A,xshift=-1.5cm] (us) {Upper System Level};

  \begin{scope}[every node/.style={minimum width=2cm,minimum height=0.5cm,rounded corners,inner sep=0pt}]
    \node [txtstyle,below of=box,yshift=-2.5cm,draw] (h1) {Master};
    \node [txtstyle,below left of=h1,yshift=-0.5cm,xshift=-2.3cm,draw] (h2) {Slave};
    \node [txtstyle,below  of=h1,yshift=-0.3cm] (h3) {...};
    \node [txtstyle,below right of=h1,yshift=-0.5cm,xshift=2.3cm,draw] (h4) {Slave};
    \node [txtstyle,above of=h2,yshift=0.3cm] (hd) {Hadooop};
  \end{scope}

  \begin{pgfonlayer}{background}
    \node[bigbox2] [fit = (hd) (h4)] (box2) {};

   \draw[<->,>=latex', shorten >=2pt, shorten <=2pt,thick] (h1.200) to (h2.north);
   \draw[<->,>=latex', shorten >=2pt, shorten <=2pt,thick] (h1.340) to (h4.north);
   \draw[->,>=latex', shorten >=2pt, thick] (box.south) to (box2.north);
     \draw[
          -triangle 90,
          line width=1.5mm,
       postaction={draw, line width=0.4cm, shorten >=0.2cm, -}
   ] (box.south) -- (box2.north);
  \end{pgfonlayer}

  \end{tikzpicture}
  \end{document}
ozsu
  • 2,385
1

The error message is about txtstyle not being defined, not about \tikzstyle. This needs to be defined somewhere so you could just say:

\tikzset{txtstyle/.style={text=black}}

or what every style you want applied when txtstyle is used.

Your code uses \tikzstyle, which should be using \tikzset as per Should \tikzset or \tikzstyle be used to define TikZ styles?.

Peter Grill
  • 223,288
  • Whoops, thanks for catching that. I missed it and the correction fixes things. I am still interested in finding a more elegant way of doing this. – ozsu Jul 12 '12 at 21:05