# Table with different column widths

I wish to create a table that has different row column size. How can i achieve something like that?

EDIT #1:

I tried

\begin{tabular}{|p{4cm}|p{2cm}|p{2cm}|p{1cm}|p{2cm}|p{3cm}|p{2cm}|} \hline
\multicolumn{4}{c}{imm[31:12]}  &   rd  & 0110111 & TEST \\\hline

\end{tabular}


And the result is this

• What have you tried? You can use m column type and \multicolumn... – user156344 May 14 '19 at 13:25
• I assumed I have to define the maximum number of columns that are being used in anycase. So since the maximum number of columns is 6 and since I wish for one more column I defined it as : \begin{tabular}{|p{4cm}|p{2cm}|p{2cm}|p{1cm}|p{2cm}|p{3cm}|p{2cm}|} \hline Now I added the first line as: \multicolumn{4}{c}{imm[31:12]} & rd & 0110111 & TEST \\\hline but the result was a failure – Broxigar May 14 '19 at 13:32
• I see you edited your question. Please don't remove necessary information - that table is needed to answer your question :) I will rollback to the previous version. – user156344 May 15 '19 at 10:29
• This is not my document, and this is why I will blurr the contents if I cant remove the matrix. – Broxigar May 15 '19 at 10:57

\documentclass{article}
\usepackage{array}
% https://tex.stackexchange.com/a/12712/156344
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{table}
\caption{Some caption for the table}
\begin{tabular}{|C{2cm}|C{1cm}|C{1cm}|C{1cm}|C{2cm}|C{1.5cm}|} \hline
\multicolumn{4}{|c|}{imm[31:12]} & rd & 0110111 \\\hline
\multicolumn{4}{|c|}{imm[31:12]} & rd & 0010111 \\\hline
\multicolumn{4}{|c|}{imm[20\textbar10:1\textbar11\textbar19:12]} & rd & 1101111 \\\hline
\multicolumn{2}{|c|}{imm[11:0]} & rs1 & 000 & rd & 1100111 \\\hline
imm[12\textbar10:5] & rs2 & rs1 & 000 & imm[4:1\textbar11] & 1100011\\\hline
\end{tabular}
\end{table}
\end{document}


with use of the makecell package for more vertical space around cells' contents, defining two new commands for shorter table's code:

\documentclass{article}
\usepackage{array, makecell}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcommand\mcF[1]{\multicolumn{4}{|c|}{#1}}
\newcommand\mcT[1]{\multicolumn{2}{|c|}{#1}}
\usepackage[skip=1ex]{caption}

\begin{document}
\begin{table}
\setcellgapes{3pt}
\makegapedcells
\centering
\caption{Some caption for the table}
\begin{tabular}{|C{20mm}|*{3}{C{13mm}|}*{2}{C{20mm}|}}
\hline
\mcF{imm[31:12]}                            & rd                    & 0110111   \\  \hline
\mcF{imm[31:12]}                            & rd                    & 0010111   \\  \hline
\mcT{imm[11:0]}             & rs1   & 000   & rd                    & 1100111   \\  \hline
imm[12\textbar10:5] & rs2   & rs1   & 000   & imm[4:1\textbar11]    & 1100011   \\  \hline
0000000             & shamt & rs1   & 001   & rd                    & 0010011   \\
\hline
\end{tabular}
\end{table}
\end{document}