0

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?

enter image description here

2
  • Welcome to TeX.SE!
    – Mensch
    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
1

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}

enter image description here

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}

enter code here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.