I am trying to create a latex table the way i am used to (no tikz matrices), but now want to use that table in tikz and draw lines from specific cells to others. Therefore I need to fit tikz nodes to my cells which also contain multicolumns and multirows.
I wonder if I can, somehow, determine the row height of the table to set the nodes minimum height to that. This at least worked for the width (since I have fixed cell widths, it was possible to calculate this).
My current code looks like this (might look disturbing):
\documentclass{standalone}
\usepackage{tikz,forloop,tabularx,tabulary,multicol,multirow,pgfmath}
\usetikzlibrary{positioning,arrows,chains,matrix,scopes,fit,calc}
\makeatletter
% 1. cols
% 2. pos
% 3. node name
% 4. text
\newcommand{\multicolx}[4]{
\multicolumn{#1}{#2}{\tikz[remember picture]{ \node[anchor=base,inner sep=0pt, draw, color=red, minimum width=#1*4mm] (#3) {#4};}}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[] (tableipv4) at (0,0)
{
\setlength{\tabcolsep}{0.0pt}
\begin{tabular}{|*{32}{m{4mm}}|}
\multicolumn{32}{|c|}{IPv4 Header}\\\hline
\multicolx{4}{|c}{tbl-ver}{Version} & \multicolx{4}{|c}{tbl-ihl}{IHL} & \multicolx{8}{|c}{tbl-tos}{Type of Service} & \multicolx{16}{|c|}{tbl-len}{Total Length}\\\hline
\multicolumn{16}{|c}{Identification} & \multicolumn{3}{|c}{Flags} & \multicolumn{13}{|c|}{Fragment Offset} \\\hline
\multicolumn{32}{|c|}{Source Address}\\\hline
\multicolumn{32}{|c|}{Destination Address}\\\hline
\multicolumn{24}{|c}{Options} & \multicolumn{8}{|c|}{Padding}\\\hline
\end{tabular}
};
\end{tikzpicture}
\end{document}
Is there any way to achieve fitting without expanding the row heights? Preferably using a latex table... But if there is something similar to multicols for tikz matrices I would consider switching :)
Thank you very much in advance
EDIT:
With John Kormylo's improvements my line heights are now fine, as you can see:
However since i have changed the remaining multicolumns to my custom multicolx I realized that it wasn't such a great idea to just multiply the length of a "bit" by the number of spanning columns. Now some nodes aren't wide enough to fill the outer multicolumn...
Updated source code:
\documentclass{standalone}
\usepackage{tikz,forloop,tabularx,tabulary,multicol,multirow,pgfmath}
\usetikzlibrary{positioning,arrows,chains,matrix,scopes,fit,calc}
\makeatletter
% 1. cols
% 2. pos
% 3. node name
% 4. text
\newcommand{\multicolx}[4]{
\multicolumn{#1}{#2}{\tikz[remember picture,baseline=(#3.text)]{ \node[anchor=base,inner sep=0pt, draw, color=red, minimum width=#1*4mm] (#3) {\strut #4};}}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[] (tableipv4) at (0,0)
{
\setlength{\tabcolsep}{0.0pt}
\begin{tabular}{|*{32}{m{4mm}}|}
\multicolumn{32}{|c|}{IPv4 Header}\\\hline
\multicolx{4}{|c}{tbl-ver}{Version} & \multicolx{4}{|c}{tbl-ihl}{IHL} & \multicolx{8}{|c}{tbl-tos}{Type of Service} & \multicolx{16}{|c|}{tbl-len}{Total Length}\\\hline
\multicolx{16}{|c}{tbl-id}{Identification} & \multicolx{3}{|c}{tbl-flag}{Flags} & \multicolx{13}{|c|}{tbl-frag}{Fragment Offset} \\\hline
\multicolx{32}{|c|}{tbl-src}{Source Address}\\\hline
\multicolx{32}{|c|}{tbl-dest}{Destination Address}\\\hline
\multicolx{24}{|c}{tbl-opts}{Options} & \multicolx{8}{|c|}{tbl-pad}{Padding}\\\hline
\end{tabular}
};
\end{tikzpicture}
\end{document}
\arraystretch\ht\strutbox
and the default depth is\arraystretch\dp\strutbox
. It appears that the default value of\arraystretch
is 1.