[Tex/LaTex] Creating process table figure in TikZ

technical-drawingtikz-pgf

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:

enter image description here

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:

enter image description here

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.

Best Answer

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}

enter image description here