# Creating process table figure in TikZ

I'm teaching operating systems course and I have to create many "process/memory map/inode table" structures for the course. For those who don't know (not sure if any of them would be here), See the figure below:

I can create the outer box and place it properly using TikZ but what would be the most efficient way of creating the different table boxes so that I can reuse them again and again in all the figures.

Update: After the rectangle split tip in the comments, I have the following:

\begin{tikzpicture}
\usetikzlibrary{shapes, positioning}

\node [draw, rectangle split=3, text width=2cm] (p1) {};

\node [left=12pt of p1, rectangle split=3, font=\tiny] {256
\nodepart {second} 255
\nodepart {third} \vdots
\nodepart {fourth} 0
};

\node [draw, rectangle split=3, text width=2cm, right=1cm of p1] (p2) {};

\node[above=12pt of p1, text width=2cm, font=\tiny, text centered] (p1l) {Per Process File Descriptor Table};
\node[above=12pt of p2, text width=2cm, font=\tiny, text centered] (p1l) {File Table};

\end{tikzpicture}


It produces the following output:

A couple of issues though:

1. How do I make the arrows?
2. The numbering on the left of the first table doesn't really match the splits in the table.
3. How do I make some boxes bigger?

Also, is this the best way to do this? Seems like the code should be clean-able a little bit more.

-
Could you please include the TikZ code you have produced so far. –  N.N. Jan 5 '12 at 11:58
Right now, I'm not looking for code. I just need a strategy -- for example, do I create a large box and draw lines in the middle. That would make it difficult to move them around as I'd be hardcoding the coordinates. Or do I create many nodes stacked on top of each other. That too looks hard to scale. –  recluze Jan 5 '12 at 11:59
Still I figure that your code might be helpful in coming up with an answer in that it serves as an example to start out with, e.g. by reducing it with \foreach and \tikzset structures. –  N.N. Jan 5 '12 at 12:33
Have a look at the rectangle split shape, it's discussed on page 450 of the TikZ manual. –  Roelof Spijker Jan 5 '12 at 12:58
It would help if you could say something about the kind of tables you need. For example, if labels are required, where can they appear. What about the relative sizes of the sub-boxes? What about the placement of the sub-boxes? What about the source and destination positions of the arrows? ..... –  Marc van Dongen Jan 5 '12 at 13:13

Further automation is certainly possible (foreach tweaks, label placement, using a tikzstyle definition for all matrix nodes instead of repeating etc. ) but I think you can furnish it more properly anyway.

Update: Added a matrix node style. You only need to input the matrices.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{table matrix/.style={draw=black,thick,inner sep=0,fill=blue!25,matrix of nodes, nodes in empty cells,%
nodes={minimum width=30mm,minimum height=3mm,draw,outer sep=0,inner sep=0},
}
}
\begin{document}
\begin{tikzpicture}
\matrix (dbtable) at (0,0) [table matrix,label={[align=center]90:{Per Process File\\Descriptor Table}}]
{
\\
\\
\\
\\
|[minimum height = 3cm]|{}\\
\\
};

\matrix (filetable) at (4,0) [table matrix,label={[align=center]90:{File Table}}]
{
\\
\\
\\
|[minimum height = 12mm]|{}\\
\\
|[minimum height = 12mm]|{}\\
\\
\\
\\
};

\foreach \x/\y in {1/0,2/1,3/2,4/3,6/OPEN\_MAX$-$1} {
\node[anchor=east] at (dbtable-\x-1.west) {\textsf{\y}};
}
\draw[yellow,-latex,ultra thick] (dbtable-3-1.center) -- (filetable-5-1.center);
\end{tikzpicture}
\end{document}


-
This looks like a lot of code -- especially since I have to make many (sometimes upto 10) such boxes in a single figure. This might get too ugly. I think I'd prefer the rectangle split approach. –  recluze Jan 6 '12 at 1:58
@recluze Not at all, you only need to define once using a style definition. I just put the example for demostration. See tikzset usage in the manual for how to do that. I will update the example. –  percusse Jan 6 '12 at 2:09
Thanks. That makes it really nice and re-usable. –  recluze Jan 6 '12 at 9:23