I'd like alternating row colors for only specific columns (and in a perfect world, also only a subset of rows), with a table using multirow and multicolumn. I've found that putting \rowcolor{COLOR}
starting with the target column works (shown below)… but it raises a misplaced \noalign
error.
I'm using TexShop (3.6.1) on OSX, with pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015)
Is there a better way to do this? Or a way to get the above method to not raise an error?
[![\documentclass\[6pt, oneside\]{article}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage\[cm\]{fullpage}
\usepackage\[table\]{xcolor}
\newcommand{\mc}\[2\]{\multicolumn{#1}{c}{#2}}
\newcommand{\mr}\[2\]{\multirow{#1}{*}{#2}}
\begin{document}
\begin{table}\centering
\renewcommand{\arraystretch}{1.2}
\setlength{\tabcolsep}{4pt}
\begin{tabular}{@{}ccc ccc lccc@{}}
\toprule
& & \mc{4}{Background} & & & & \\
\mr{2}{One Column} & \mr{2}{Two Column}& \mc{2}{Amp} & \mc{2}{Spectrum} & \mr{2}{Subset} & Stuff & \mc{2}{\mr{2}{Fraction}} \\
& & $1$ & $0.1$ & $1$ & $0.1$ & & All (Coal) & \mc{2}{} \\\midrule
\mr{8}{Stuff} & \mr{4}{0.6} & \mr{4}{3.7} & \mr{4}{15} & \mr{4}{-3}& \mr{4}{-0.59} & \rowcolor{blue!20}All & 29 (2.7) & $ 1875/ 9270$ & $(0.20)$ \\
& & & & & & \rowcolor{blue!30}$\mu>0.2$ & 26 (2.2) & $ 1225/ 4759$ & $(0.26)$ \\
& & & & & & \rowcolor{blue!20}$M>10^8$ & 17 (4.0) & $ 608 / 2610$ & $(0.23)$ \\
& & & & & & \rowcolor{blue!30}$M>10^8$,$\mu>0.2$& 6.9 (3.3) & $ 214 / 478$ & $(0.45)$ \\
& \mr{4}{1.0} & \mr{4}{4.7} & \mr{4}{17} & \mr{4}{-6}& \mr{4}{-0.38} & \rowcolor{blue!10}All & 7.7 (1.2) & $ 4634/ 9270$ & $(0.50)$ \\
& & & & & & \rowcolor{blue!20}$\mu>0.2$ & 4.8 (1.0) & $ 2900/ 4759$ & $(0.61)$ \\
& & & & & & \rowcolor{blue!10}$M>10^8$, & 4.9 (0.79) & $ 1422/ 2610$ & $(0.54)$ \\
& & & & & & \rowcolor{blue!20}$M>10^8$,$\mu>0.2$& 0.35 (0.35) & $ 472/ 478$ & $(0.99)$ \\
\bottomrule
\end{tabular}
\caption{}
\label{tab:params}
\end{table}
\end{document}][1]][1]
Best Answer
To obtain above image I first clean-up your code. It contain bunch of errors caused by wrong use options (they had to be inside
[...]
and not in math environment\[...\]
). Then to each cell, which you like to have colored, wrote\cellcolor{<selected color>}
. This is only way (for which I know) that you have only part row in desired color. To simplify this task (since all colors ara based on blue), I defined new command:and (after lot of work) I rewrote your MWE into: