3

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

3

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

2

A solution with the makecell (allows for line breaks in cells), cellspace (better vertical spacing above and below cells) and hhline(allows for multicoloured hlines):

\documentclass{article}

\usepackage{amsmath}
\usepackage{multirow, makecell, colortbl, hhline}
\usepackage{xcolor}
\usepackage{cellspace}
\setlength\cellspacetoplimit{3pt}
\setlength\cellspacebottomlimit{3pt}

\begin{document}
\begin{table}[h]
\setlength\tabcolsep{10pt}\setlength\arrayrulewidth{1pt}
\sffamily\bfseries
\begin{tabular}{>{\columncolor{black}\color{white}}c!{\color{white}\vline width1pt} >{\columncolor{black}\color{white}}c *{4}{Sc|}}
\cline{3-6}
\rowcolor{black} \multicolumn{2}{c|}{\cellcolor{white}} & \color{white}M1 &\color{white} M2 &\color{white} M3 & \color{white}M4 \\
\hhline{>{\arrayrulecolor{white}}-->{\arrayrulecolor{black}}|----}
\makebox[1cm]{A1}& \makecell{a1 \quad a2\\b\\c} & \makecell{0,3 \quad 0,5\\3\\1} &\makecell{ 0,1 \quad 0,2\\2\\0} &\makecell{ 0,3 \quad 0,8\\0.1\\$ \boldsymbol - $5} & \makecell{0,4 \quad 0,7\\1\\3} \\
\hhline{>{\arrayrulecolor{white}}-->{\arrayrulecolor{black}}----}
A2 & \makecell{a1 \quad a2\\b\\c} & \makecell{0,3 \quad 0,5\\3\\1} & \makecell{0,1 \quad 0,2\\2\\0} & \makecell{4 \quad 2\\0.1\\$ \boldsymbol - $5} & \makecell{0,1 \quad 0,2\\1\\-2} \\
\hhline{>{\arrayrulecolor{white}}-->{\arrayrulecolor{black}}----}
A3 & \makecell{a1 \quad a2\\b\\c} & \makecell{0,3 \quad 0,5\\3\\1} & \makecell{0,1 \quad 0,2\\2\\0} & \makecell{4 \quad 2\\0.1\\$\boldsymbol - $5} & \makecell{0,1 \quad 0,2\\1\\$\boldsymbol - $2} \\
\hhline{>{\arrayrulecolor{white}}-->{\arrayrulecolor{black}}----}
\end{tabular}
\end{table}
\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.