# Rowcolor, Multicolumn, and Tabu

Ok, I want to create an environment that prepares my table in such a way that I have consistent results.

\documentclass[10pt]{article}

\usepackage[table]{xcolor}

\usepackage{graphics}
\usepackage{colortbl} %make alternating row colours

\usepackage{tabu} % \rowfont

\usepackage{multirow} % for multirow and multicol
\usepackage{booktabs}
\usepackage{hhline} %to make hlines over a certain number of columns

\usepackage{array} % adds more features on how tables are used
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}} %left-align with specific size
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}%centre-align with specific size
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\rowcolors{2}{blue!15}{white}
\arrayrulecolor{blue}

\newenvironment{myTable}[4][htbp]
{
\begin{table}[#1]
\begin{center}
\caption{#4}\label{#3}

\begin{tabu}{#2}
\hline
}{
\end{tabu}
\end{center}
\end{table}
}

\begin{document}

\begin{myTable}[htb]{*{4}{c |}|*{2}{C{1.5cm} |}| C{3cm}}%
{tbl:label}%
{Caption Text}
\theader$a$ & $b$ & $c$ & $d$ & $(a\land b)$ & $(c\land d)$ & $(a\land b)\lor(c\land d)$\\\hline
0 & 0 & 0 & 0 & 0 & 0 & 0\\
\multicolumn{4}{@{}c@{}}{\upbracefill} & \multicolumn{2}{@{}c@{}}{\upbracefill} & \upbracefill\\
\end{myTable}
\end{document}


I create an environment myTable that contains a table and tabu environment. However, whenever I use \multicolumn together with \rowcolor. I get the following compiler error:

! Emergency stop. \multispan ->\omit @multispan l.46 \end{myTable}

I had the same within a tabular environment and it worked fine. When I remove the multicolumn commands, it works fine. When I remove the rowcolor command, it works fine.

I can work around it by placing a \cellcolor{white} in each multicolumn command. But that's not a solution.

Does anybody has any ideas on how to fix it??? Any help is appreciated!

• Tabu is currently unmaintained and causes some undesired behavior especially when convinced with color. I'd suggest switching to an alternative such as tabularx. May 5, 2020 at 15:09
• Welcome to TeX.SE... It is not advisable to use the package tabu... Better switch over to normal tabular with colortbl support.... May 5, 2020 at 16:16
• OK, [colortbl] is fine but I need tabu for the [\rowfont] command. (I need to set the font color for the entire row). Is there an alternative? May 6, 2020 at 21:04

Another option would be the new tabularray package. The package allows you to completely separate the format from the content. It support cells spanning multiple columns and rows and coloring.

\documentclass[10pt]{article}

\usepackage{xcolor}
\usepackage{tabularray}

\NewColumnType{C}[1]{Q[c,wd=#1]}

\newenvironment{myTable}[4][htbp]
{
\begin{table}[#1]
\centering
\caption{#4}\label{#3}
\begin{tblr}{
colspec={#2},
hline{1-Y}={blue},
vline{1-Z}={1}{1-Y}{blue}, vline{5, 7}={2}{1-Y}{blue},
row{even}={white}, row{odd}={blue!15},
row{1}={bg=blue, fg=white, mode=math},
row{Z}={white, rowsep=0pt},
}
}{
\end{tblr}
\end{table}
}

\begin{document}

\begin{myTable}{*{4}{c}*{2}{C{1.5cm}}C{3cm}}%
{tbl:label}%
{Caption Text}
a & b & c & d & (a\land b) & (c\land d) & (a\land b)\lor(c\land d) \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
\SetCell[c=4]{c} \raisebox{2mm}{$\underbrace{\hspace{2cm}}$} & & & & \SetCell[c=2]{c} \raisebox{2mm}{$\underbrace{\hspace{4cm}}$} & & \raisebox{2mm}{$\underbrace{\hspace{3cm}}$} \\
\end{myTable}

\end{document}


Which produces the output:

You can specify the format using row and column parameters, e.q. I used the setting mode=math so you don't have to write  every time in the first row.

• this is a really good package!.. instructions are a bit happy.. but I worked it out :) Apr 5 at 0:45