# How To Color A Single Multicolumn Cell

I am trying to color individual cells inside of a table containing multicolumn cells, however Using \colorcell, or \columncolor results in cells which have white padding on the right hand side.

I have found relevant questions, however they all seem to be concerned with coloring non-multicolumn cells within a table containing multicolumns. However I am concerned with coloring the multicolumn cell itself.

ie.

Table cell color overlaps left cell border of first column which is multicolumn

How to color only one cell in a multicolumn table?

I have tried the following, however none of them quite work. The method with setting \tabcolsep to 0pt is the closest to wht I want, however I don't like how the text goes all the way to the vertical line.

\documentclass{report}
\usepackage{tabularx,colortbl,ltablex}
\renewcommand\tabularxcolumn[1]{m{#1}}% for vertical centering text in X column
\newcolumntype{C}{>{\centering\arraybackslash}X}

\newcommand{\cell}[2]{\multicolumn{#1}{|>{\hsize=#1\hsize}C|}{#2}}
\newcommand{\colorcell}[2]{\multicolumn{#1}{|>{\columncolor{red}\hsize=#1\hsize}C|}{#2}}
\newcommand{\colorcellb}[2]{\multicolumn{#1}{|>{\columncolor{red}[\tabcolsep][#1\tabcolsep]\hsize=#1\hsize}C|}{#2}}

\begin{document}
\keepXColumns

Standard Column Color
\begin{tabularx}{\textwidth}{|*{8}{C|}}
\hline
7&6&5&4&3&2&1&0\\
\hline
\colorcell{1}{ a a a a a a a a a a a a}&\cell{1}{CLEAR}&\colorcell{2}{Colored Cell}&\cell{1}{CLEAR}&\colorcell{3}{Colored Cell}\\
\hline
\end{tabularx}

ColumnColor + Overhangs
\begin{tabularx}{\textwidth}{|*{8}{C|}}
\hline
7&6&5&4&3&2&1&0\\
\hline
\colorcellb{1}{ a a a a a a a a a a a a}&\cell{1}{CLEAR}&\colorcellb{2}{Colored Cell}&\cell{1}{CLEAR}&\colorcellb{3}{Colored Cell}\\
\hline
\end{tabularx}

TabColSep=0
\setlength{\tabcolsep}{0 pt}
\begin{tabularx}{\textwidth}{|*{8}{C|}}
\hline
7&6&5&4&3&2&1&0\\
\hline
\colorcell{1}{ a a a a a a a a a a a a}&\cell{1}{CLEAR}&\colorcell{2}{Colored Cell}&\cell{1}{CLEAR}&\colorcell{3}{Colored Cell}\\
\hline
\end{tabularx}

\end{document}


• Welcome to TeX.SX! Aug 28 '18 at 14:43

like this:

in calculation of multi column width you forgoth on \tabcolsep and \arrayrulewidth. considering them in your definition of new comeands cell (actually is unnecessary in your mwe)- considering it your mwe become:

\documentclass{report}
\usepackage[table]{xcolor}
\usepackage{ltablex}
\keepXColumns
\renewcommand\tabularxcolumn[1]{m{#1}}% for vertical centering text in X column
\newcolumntype{C}{>{\centering\arraybackslash}X}

\newcommand{\cell}[2]{\multicolumn{#1}{|>{\hsize=%
\dimexpr#1\linewidth+#1\tabcolsep+#1\tabcolsep-#1\arrayrulewidth}C|}{#2}}
\newcommand{\colorcell}[2]{\multicolumn{#1}{|>{\columncolor{red}\hsize=%
\dimexpr#1\linewidth+#1\tabcolsep+#1\tabcolsep-#1\arrayrulewidth}C|}{#2}}

\begin{document}

Standard Column Color

\begin{tabularx}{\textwidth}{|*{8}{C|}}
\hline
7 & 6 & 5 & 4 & 3 & 2 & 1 & 0     \\
\hline
\colorcell{1}{ a a a a a a a a a a a a}
&  CLEAR
&   \colorcell{2}{Colored Cell}
&   CLEAR
&   \colorcell{3}{Colored Cell}     \\
\hline
\end{tabularx}

\end{document}

• Thank You!! I would mark as accepted, but apparently asked from an unregistered account Aug 28 '18 at 15:27
• @DanChianucci, don't rush with acceptance :-), however register your account :-) Aug 28 '18 at 15:30