[Tex/LaTex] How to avoid \cellcolor overflowing when changing the space in the column

colortables

I reduced the space in the columns through the use of @{} in the column type:

\newcolumntype{M}{@{}c@{}}

The problem is that, when I combined this with the \cellcolor command, it overflows into the other columns. And if I remove the @{} space modification, then it sets it right.

So, how can I let the \cellcolor command now that I reduced the space of that column?

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{array}
\newcolumntype{M}{@{}c@{}}

\begin{document}
\pagestyle{empty}
\begin{table}
\begin{tabular}{l|M|c|M|M}
  & a & b & c & d\\
a & \cellcolor{black!50} 90.6 & 10 & 0 & 0\\
b & 0 & \cellcolor{black!50} 90.0 & 10 & 10\\
c & 0 & 0 & 95 & \cellcolor{black!50} 5\\
d & 0 & 10 & 5.5 & 8\\
\end{tabular}
\end{table}
\end{document}

Overflowed cellcolor table

Best Answer

fake the columncolor:

\documentclass{standalone}

\usepackage[table]{xcolor}
\usepackage{array}
\newcolumntype{M}{@{}>{\columncolor{white}[0pt][0pt]}c@{}}

\begin{document}
\pagestyle{empty}
\begin{table}
\begin{tabular}{l|M|c|M|M}
  & a & b & c & d\\
a & \cellcolor{black!50} 90.6 & 10 & 0 & 0\\
b & 0 & \cellcolor{black!50} 90.0 & 10 & 10\\
c & 0 & 0 & 95 & \cellcolor{black!50} 5\\
d & 0 & 10 & 5.5 & 8\\
\end{tabular}
\end{table}
\end{document}

enter image description here

However, you'll get problems with viewing the vertical lines. With some zoom values they will not be visible. Printing is no problem.