# Tables with fixed column size yield different table length

I am quite new to the latex with some features of details.

I have tried to have tables that look like a memory layout and the codes are as follows. I found a way to create a fixed sized column like this.

\documentclass{article}

\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{| @{}C{0.5cm}@{} | @{}C{7cm}@{} | @{}C{5cm}@{} | @{}C{0.5cm}@{} |}
\hline
$p$ & $C_{1}$& $C_{2}$ & $q$ \\
\hline
\end{tabular}

\begin{tabular}{| @{}C{0.5cm}@{} | @{}C{3cm}@{} | @{}C{3cm}@{} | @{}C{1cm}@{} | @{}C{5cm}@{} | @{}C{0.5cm}@{} |}
\hline
$p$ & $C_{11}$ & $C_{13}$ & $C_{12}$ & $C_{2}$ & $q$ \\
\hline
\end{tabular}

\end{table}

\end{document}


So, what I wanted is to divide the second column of the first table into three columns but with the same size. However, for some reasons, second table is very slightly bigger than the first one. What is the reason for this? and can I get the same sized tables with this code?

• Welcome to TeX.SE! Nov 14 '21 at 22:53
• you need to take account of \arrayrulewidth one has 5 and the other has 7 use C{\dimexpr 7cm+2\arrayrulewidth} Nov 14 '21 at 22:57

If you don't plan on subdividing columns too much, you can use \multicolumn and easily make both rows in the same table and not worry too much about the \arrayrulewidth.

\documentclass{article}

\usepackage{array}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{| @{}C{0.5cm}@{} | @{}C{3cm}@{} | @{}C{3cm}@{} | @{}C{1cm}@{} | @{}C{5cm}@{} | @{}C{0.5cm}@{} |}
\hline
$p$ & \multicolumn{3}{c|}{$C_{1}$}      & $C_{2}$ & $q$ \\ \hline
$p$ & $C_{11}$ & $C_{13}$ & $C_{12}$    & $C_{2}$ & $q$ \\\hline
\end{tabular}
\end{table}
\end{document}


You might also find the bytefield package to be helpful making these sorts of tables:

\documentclass{article}
\usepackage{bytefield}
\begin{document}
\begin{bytefield}{32}
\bitbox{2}{$p$} & \bitbox{14}{$C_1$} & \bitbox{14}{$C_2$} & \bitbox{2}{$p$} \\
\bitbox{2}{$p$} & \bitbox{6}{$C_{11}$} & \bitbox{6}{$C_{13}$} & \bitbox{2}{$C_{12}$} & \bitbox{14}{$C_2$} & \bitbox{2}{$p$} \\
\end{bytefield}
\end{document}