[Tex/LaTex] Color in Table with Multicolumn and Multirow – How to achieve

colormulticolumnmultirowtables

Yet another question, this time with coloring the table. This is the code for the table I got with your help here:

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[h]
\begin{tabular}{*{6}{|c}|}
\cline{3-6}
\multicolumn{2}{c|}{} & M1          & M2            & M3           & M4            \\ \hline
\multirow{3}{*}{A1}  & a1 \quad a2 & 0,3 \quad 0,5 & 0,1 \quad 0,2 & 0,3 \quad 0,8 & 0,4 \quad 0,7 \\
                     & b           & 3             & 2             & 0,1           & 1             \\
                     & c           & 1             & 0             & -5            & 3             \\ \hline
\multirow{3}{*}{A2}  & a1 \quad a2 & 0,3 \quad 0,5 & 0,1 \quad 0,2 & 4 \quad 2     & 0,1 \quad 0,2 \\
                     & b           & 3             & 2             & 0,1           & 1             \\
                     & c           & 1             & 0             & -5            & -2            \\ \hline
 \multirow{3}{*}{A3} & a1 \quad a2 & 0,3 \quad 0,5 & 0,1 \quad 0,2 & 4 \quad 2     & 0,1 \quad 0,2 \\
                     & b           & 3             & 2             & 0,1           & 1             \\
                     & c           & 1             & 0             & -5            & -2            \\ \hline
\end{tabular}
\end{table}
\end{document} 

How can I color the table to look like it as follows? Many thanks in advance.

http://i.imgur.com/AY3XwgY.png

Best Answer

A bit complicated...

\documentclass{article}
\usepackage{multirow}
\usepackage[table]{xcolor}
\begin{document}
\begin{table}[h]
\begin{tabular}{|*{2}{>{\columncolor{black}\color{white}}c}*{4}{|c}|}
\cline{3-6}
\rowcolor{black}\multicolumn{2}{c|}{\cellcolor{white}{}} 
                     & \textcolor{white}{M1}          
                     & \textcolor{white}{M2}            
                     & \textcolor{white}{M3}           
                     & \textcolor{white}{M4}            \\ \hline
                     & a1 \quad a2 & 0,3 \quad 0,5 & 0,1 \quad 0,2 & 0,3 \quad 0,8 & 0,4 \quad 0,7 \\
                     & b           & 3             & 2             & 0,1           & 1             \\
\multirow{-3}{*}{A1} & c           & 1             & 0             & -5            & 3             \\ \hline  
                     & a1 \quad a2 & 0,3 \quad 0,5 & 0,1 \quad 0,2 & 4 \quad 2     & 0,1 \quad 0,2 \\
                     & b           & 3             & 2             & 0,1           & 1             \\
\multirow{-3}{*}{A2} & c           & 1             & 0             & -5            & -2            \\ \hline
                     & a1 \quad a2 & 0,3 \quad 0,5 & 0,1 \quad 0,2 & 4 \quad 2     & 0,1 \quad 0,2 \\
                     & b           & 3             & 2             & 0,1           & 1             \\
\multirow{-3}{*}{A3} & c           & 1             & 0             & -5            & -2            \\ \hline
\end{tabular}
\end{table}
\end{document} 

enter image description here