# tcolorbox, tabularx: first line with a multicolumn does not work in tcolorbox environment

I have a problem with tabularx in a tcolorbox environment, here is the code:

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[most]{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}

\begin{document}

\newcolumntype{b}{X}
\newcolumntype{i}{>{\hsize=.005\hsize}X}
\newcolumntype{s}{>{\hsize=.15\hsize}X}

\begin{table}
\begin{center}
\begin{tcolorbox}[colback=black!0.8!white,colframe=black!4!white,
colbacktitle=gray!40!white, coltitle=black,width=1.0\linewidth,tabularx={ibs}]
\multicolumn{2}{b}{Number}                           & 11     \\\hline
& part a                                             & 38     \\\hline
& part b                                             & 4      \\\hline
& part c                                             & 2      \\\hline\hline
\multicolumn{2}{l}{Blabla 1}                         & 217    \\\hline
\multicolumn{2}{l}{Blabla 2}                         & 20     \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 105    \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 3100   \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 367
\end{tcolorbox}
\end{center}
\end{table}

\vspace{3cm}

\begin{center}
\begin{tabularx}{1.0\linewidth}{ibs}
\multicolumn{2}{b}{Number}                           & 11     \\\hline
& part a                                             & 38     \\\hline
& part b                                             & 4      \\\hline
& part c                                             & 2      \\\hline\hline
\multicolumn{2}{l}{Blabla 1}                         & 217    \\\hline
\multicolumn{2}{l}{Blabla 2}                         & 20     \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 105    \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 3100   \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 367\end{tabularx}
\end{center}

\vspace{3cm}

\end{document}


In a regular tabularx environment, the table is okay (see 2nd table). However, if I do the same in a tcolorbox environment (1st table), the first line, which contains a multicolumn, does not work, whereas the other 5 show up, if one passes all the errors.

The error is (appears 6x):

! Misplaced \omit.
\multispan ->\omit
\@multispan
l.31 \end{tcolorbox}

?


I tried to play with the 'size' of the first multicolumn but did not succeed.

Any help is highly appreciated. Thanks.

• unrelated to the error but your ibs heading is wrong , you have 3 X columns so the total width should be 3\hsize and 1+.005+.15 is not 3, tabularx will most likely fail to converge to sensible size given that input. – David Carlisle Jan 30 '17 at 11:09
• David: If I use 2.845+.005+.15 = 3, everything is put to the left of the table. – Krumpel Jan 30 '17 at 11:23
• I do not know your intended design but any output made by tabularx given widths of 1+.005+.15 is entirely accidental , there is only one rule in the tabularx documentation and that is, don't do that:-) – David Carlisle Jan 30 '17 at 11:29
• I agree since I found your example below ... . Sorry, I couldn't wait. ;-) – Krumpel Jan 30 '17 at 11:38

It's easiest to just put the \multicolumn in the second row, leaving an empty first row that you can back up with a negative vspace. I also fixed your ibs definitions.

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[most]{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}

\begin{document}

\newcolumntype{b}{>{\hsize=2.8\hsize}X}
\newcolumntype{i}{>{\hsize=.05\hsize}X}
\newcolumntype{s}{>{\hsize=.15\hsize}X}

\begin{table}
\begin{center}
\errorcontextlines400
\tracingonline2

%\tracingall
\begin{tcolorbox}[colback=black!0.8!white,colframe=black!4!white,
colbacktitle=gray!40!white, coltitle=black,width=1.0\linewidth,tabularx={ibs}]%
\\
\noalign{\vspace{-\normalbaselineskip}}
\multicolumn{2}{b}{Number}
& 11     \\\hline
& part a                                             & 38     \\\hline
& part b                                             & 4      \\\hline
& part c                                             & 2      \\\hline\hline
\multicolumn{2}{l}{Blabla 1}                         & 217    \\\hline
\multicolumn{2}{l}{Blabla 2}                         & 20     \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 105    \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 3100   \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 367
\end{tcolorbox}
\end{center}
\end{table}

\vspace{3cm}

\begin{center}
\begin{tabularx}{1.0\linewidth}{ibs}
\multicolumn{2}{b}{Number}                           & 11     \\\hline
& part a                                             & 38     \\\hline
& part b                                             & 4      \\\hline
& part c                                             & 2      \\\hline\hline
\multicolumn{2}{l}{Blabla 1}                         & 217    \\\hline
\multicolumn{2}{l}{Blabla 2}                         & 20     \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 105    \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 3100   \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 367\end{tabularx}
\end{center}

\vspace{3cm}

\end{document}

• Excellent, thanks a lot, it works! Q: Why must one insert first an empty row? Is that due to a 'bug'? – Krumpel Jan 30 '17 at 11:39
• @Krumpel \multicolumn has to be the first thing in the cell otherwise the cell template gets added and it is too late to substitute the spanning information. even invisible stuff like relax or {} is enough to break it. So somewhere in the many lines of tcolorbox keyval processing it is is constructing a call to tabularx with {} or \relax or something:-) after the {ibs} argument. I could spend a day tracing where but it's easier to write off that row and start again on the next row:-) (it may be worth giving the tcolorbox author a link to this, would be easier for him to trace) – David Carlisle Jan 30 '17 at 11:47
• @Krumpel This is a tcolorbox bug, which has been reported today. By the moment, Thomas F. Sturm has provided a provisional hack to solve the problem. You can see how to use it in the update section of this answer – Ignasi Feb 20 '19 at 16:00

This problem has been solved with tcolorbox v4.20. Now, multicolumn option can be used in top most row without problems.

OP's code

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[most]{tcolorbox}
\usepackage{tabularx}
\usepackage{array}
\usepackage{colortbl}
\tcbuselibrary{skins}

\begin{document}

\newcolumntype{b}{X}
\newcolumntype{i}{>{\hsize=.005\hsize}X}
\newcolumntype{s}{>{\hsize=.15\hsize}X}

\begin{table}
\begin{center}
\begin{tcolorbox}[colback=black!0.8!white,colframe=black!4!white,
colbacktitle=gray!40!white, coltitle=black,width=1.0\linewidth,tabularx={ibs}]
\multicolumn{2}{b}{Number}                           & 11     \\\hline
& part a                                             & 38     \\\hline
& part b                                             & 4      \\\hline
& part c                                             & 2      \\\hline\hline
\multicolumn{2}{l}{Blabla 1}                         & 217    \\\hline
\multicolumn{2}{l}{Blabla 2}                         & 20     \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 105    \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 3100   \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 367
\end{tcolorbox}
\end{center}
\end{table}

\vspace{3cm}

\begin{center}
\begin{tabularx}{1.0\linewidth}{ibs}
\multicolumn{2}{b}{Number}                           & 11     \\\hline
& part a                                             & 38     \\\hline
& part b                                             & 4      \\\hline
& part c                                             & 2      \\\hline\hline
\multicolumn{2}{l}{Blabla 1}                         & 217    \\\hline
\multicolumn{2}{l}{Blabla 2}                         & 20     \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 105    \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 3100   \\\hline
\multicolumn{2}{l}{Blabla 1}                         & 367\end{tabularx}
\end{center}

\vspace{3cm}

\end{document}


produces the expected result without any error message