# Multicolumn table format problem

I have been reading some very nice answers on this site on how to construct tables. I am showing below what I have written.

\documentclass[11pt]{article}
\usepackage{float}
\usepackage{multirow}
\usepackage{cite}

\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{c|c|c|c|c|c|c|c|c|}
\multicolumn{4}{c}{}
& \multicolumn{4}{c}{$n$} \\ \cline{3-8}
\multicolumn{2}{c|}{}
& $0$ & $1$ & $2$ & $3$ \\ \cline{2-8}
\multirow{4}{*}{$\ell$}
& $0$ & a & b & c & d \\ \cline{2-8}
& $1$ & a & b & c & d \\ \cline{2-8}
& $2$ & a & b & c & d \\ \cline{2-8}
& $3$ & a & b & c & d \\ \cline{2-8}
\end{tabular}
\caption{test table.}
\label{tab: test}
\end{table}
\end{document}


which results in

I do not understand what and why things are going wrong in the final column and is not presented like the others. Any help would be appreciated. Also, I would appreciate a minimal example to generalise this to a bigger matrix if that's not too much trouble.

• Welcome to TeX.SX! You define a total of 9 columns, but as far as I can tell, you will only need 6 for you table. – leandriis Nov 10 '19 at 14:10

In the following example, I have removed superfluous column specifiers (you had a total of 9 but your table only needs 6 of them). I have accordingly adapted the \cline commands to fit the respective column numbers and replaced \multicolumn{4}{c}{} with \multicolumn{2}{c}{}. I have also removed unnecessary math mode.

\documentclass[11pt]{article}
\usepackage{float}
\usepackage{multirow}
\usepackage{cite}

\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{c|c|c|c|c|c|}
\multicolumn{2}{c}{}     & \multicolumn{4}{c}{$n$} \\ \cline{3-6}
\multicolumn{2}{c|}{}        & 0 & 1 & 2 & 3       \\ \cline{2-6}
\multirow{4}{*}{$\ell$}  & 0 & a & b & c & d       \\ \cline{2-6}
& 1 & a & b & c & d       \\ \cline{2-6}
& 2 & a & b & c & d       \\ \cline{2-6}
& 3 & a & b & c & d       \\ \cline{2-6}
\end{tabular}
\caption{test table.}
\label{tab: test}
\end{table}
\end{document}


If you want to adapt this solution to a bigger table, you will have to add the correnponding amount of column specifiers, modify the \multicolumn{4}{c}{$n$} and \multirow{4}{*}{$\ell$} commands to correctly center the respective headers and also adapt the \cline commands according to your new maximum number of columns.

Here is the correnponding code for a larger table, in which a did the above mentioned changes:

\documentclass[11pt]{article}
\usepackage{float}
\usepackage{multirow}
\usepackage{cite}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{c|c|c|c|c|c|c|c|}
\multicolumn{2}{c}{}     & \multicolumn{6}{c}{$n$}    \\ \cline{3-8}
\multicolumn{2}{c|}{}        & 0 & 1 & 2 & 3 & 4 & 5  \\ \cline{2-8}
\multirow{6}{*}{$\ell$}  & 0 & a & b & c & d & e & f  \\ \cline{2-8}
& 1 & a & b & c & d & e & f  \\ \cline{2-8}
& 2 & a & b & c & d & e & f  \\ \cline{2-8}
& 3 & a & b & c & d & e & f  \\ \cline{2-8}
& 4 & a & b & c & d & e & f  \\ \cline{2-8}
& 5 & a & b & c & d & e & f  \\ \cline{2-8}
\end{tabular}
\caption{test table.}
\label{tab: test}
\end{table}
\end{document}

• Thanks for the detailed answer. Really appreciate it! – DiSp0sablE_H3r0 Nov 10 '19 at 14:17
• @A_user_with_NoName: You're welcome. I have also added a short explanation about the necessary changes if you want to get this kind of table with more columns and rows. I have also included a small example on that as well. – leandriis Nov 10 '19 at 14:23