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 need to reproduce a frequency allocation diagram in TeX. I prefer TikZ but open to PSTricks. I can create a simple bar allocation char using \node but unsure how to create layered blocks like the dark blue Public Safety / Broadband / Guardband / LMR block in the below graphic example.

Source Image

My current code is very very wrong. The blocks are a set size, the the block length needs to correspond to the how much frequency is allocated; nor are the blocks touching. Can we write a macro that draws the block based on some input length?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}[node distance = 4cm, auto]

\tikzstyle{boxT}=[rectangle, draw=black!50, fill=teal, minimum width=5em, minimum height=3em, level distance=10cm,align=center, anchor=north, text=black, text width = 2.75cm]

\tikzstyle{boxB}=[rectangle, draw=black!50, fill=blue, minimum width=5em, minimum height=3em, level distance=10cm,align=center, anchor=north, text=white, text width = 2.75cm]

\node [boxT] (a) {Commercial};
\node [boxT, right of=a] (b) {Commercial};
\node [boxT, right of=b] (c) {D Block};
\node [boxB, right of=c] (d) {Broadband};
\node [boxB, right of=d] (e) {Guardband};
\node [boxB, above of=e] (f) {Public Safety};   

\end{tikzpicture}
\end{figure}
\end{document}
share|improve this question
1  
That looks a little bit like How to draw multiple Rectangles from input data file. Show us the code, preferable in a MWE, on what you accomplished so far by your self and list where you ran into troubles. Looks just like a couple of nodes and/or rectangular paths to me. –  Qrrbrbirlbel Apr 24 '13 at 18:29
    
Don’t use right of=, but use the positioning library and right=of. — You can simply use \node [boxT, text width=<necessary length>] (a) {Commercial}; Although, a combination with the chains library and a few good styles would be better … –  Qrrbrbirlbel Apr 24 '13 at 20:24
    
@Qrrbrbirlbel, I am not familiar with the chains library, can you provide an example? –  Elpezmuerto Apr 24 '13 at 20:52

1 Answer 1

up vote 4 down vote accepted

Here's some initial code that you can use as a starting point (I didn't place all the labels); the idea was to use some predefined styles and two chains:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,chains,positioning,patterns,calc}

\tikzset{
boxT/.style={
  draw=none,
  rectangle,
  fill=teal!70,
  align=center,
  anchor=north,text width = 2.75cm,
  text height=5ex,
  text depth=2.5ex,
},
boxB/.style={boxT,text width=0.5cm,pin={[yshift=-6pt]below:Commercial}},
boxC/.style={boxT,text width=0.5cm,pin={[yshift=-6pt]below:Guardband}},
boxD/.style={boxT,fill=orange!90!black,text width=4.5cm,},
pinA/.style={
  pin={[yshift=10pt]below:%
    \tikz\node[inner sep=3pt,fill=orange!90!black,rounded corners] {Guardband};}},
boxE/.style={boxT,text width=#1},
boxF/.style={boxT,fill=orange!90!black,text width=#1},
boxG/.style={boxT,pattern=north east lines,text width=#1},
}

\newcommand\thtext[4]{%
  \node [boxD,on chain] (#1) {};
  \draw[white,line width=1pt] (#1.west) -- coordinate[pos=0.43] (aux1) coordinate[pos=0.57] (aux2) (#1.east);
  \draw[white,line width=1pt] (aux1) -- (aux1|-#1.south);
  \draw[white,line width=1pt] (aux2) -- (aux2|-#1.south);
  \node[label=below:{#2}] at (#1.north) {};
  \node[label={[xshift=-1.45cm]above:{#3}},anchor=west] at (#1.south) {};
  \node[label={[xshift=1.45cm]above:{#4}},anchor=east] at (#1.south) {};
}

\begin{document}

\begin{tikzpicture}[
  scale=0.7,
  transform shape,
  start chain,
  node distance=2pt,
  every pin edge/.style={*-,shorten <=-10pt}
]

\node[boxT,on chain] (a) {Commercial};
\node[boxB,on chain] (b) {};
\node[boxT,on chain] (c) {D Block};
\node[boxC,on chain] (d) {};
\thtext{e}{Public safety}{Broadband}{LMR}
\node[boxB,on chain] (f) {};   
\node[boxT,on chain] (g) {Commercial};
\node[boxC,on chain] (h) {};
\node[boxT,on chain] (i) {D Block};
\thtext{j}{Public safety}{Broadband}{LMR}
\node[boxB,on chain] (k) {};

\node[pinA] at (e.south) {};
\node[pinA] at (j.south) {};

\begin{scope}[start chain=1,yshift=4cm,node distance=0pt,outer sep=0pt]
\node[boxE=1cm,on chain=1,anchor=east] (a1) {};
\node[boxF=25pt,on chain=1] (b1) {};
\node[boxE=3cm,on chain=1] (c1) {};
\node[boxF=20pt,on chain=1] (d1) {};
\node[boxE=3cm,on chain=1] (e1) {};
\node[boxG=5pt,on chain=1] (f1) {};
\node[boxE=20pt,on chain=1] (g1) {};
\node[boxF=20pt,on chain=1] (h1) {};
\node[boxE=2pt,on chain=1] (i1) {};
\node[boxG=25pt,on chain=1] (j1) {};
\node[boxE=20pt,on chain=1] (k1) {};
\node[boxF=15pt,on chain=1] (l1) {};
\node[boxE=45pt,on chain=1] (m1) {};
\node[boxF=15pt,on chain=1] (n1) {};
\node[boxE=4cm,on chain=1] (o1) {};
\node[boxF=15pt,on chain=1] (p1) {};
\node[boxE=2.5cm,on chain=1] (q1) {};
\end{scope}
\draw[dashed] (a.north west) -- ( $ (k1) + (0,-30pt) $ ) -- (k1.north);
\draw[dashed] (k.north east) -- ( $ (l1) + (0,-30pt) $ ) -- (l1.north);
\end{tikzpicture}

\end{document}

enter image description here

The command \thtext has four arguments:

\thtext{<name>}{<Upper text>}{<Lower left text>}{<Lower right text>}

where <name> is the name for the node, and the other argumets are self explanatory; for example (with the styles defined above),

\thtext{kk}{Upper}{Lower L}{Lower R}

will produce a node called kk and with the following layout:

enter image description here

share|improve this answer

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.