[Tex/LaTex] How to color rows when using makecell

colormakecelltables

I'd like to color the rows of a table to make it easy readable. Some cells have multiple lines, so I use the makecell package, and planned to use the xcolor for coloring, but they are clashing. Sample code:

\documentclass{article}
\usepackage{makecell}
%\usepackage[table]{xcolor}
\usepackage{bpchem}

\begin{document}
    %\rowcolors[1]{gray!25}{white}
    \begin{tabular}{ccc}
        \BPChem{H\_2O}&\BPChem{H\_3N}&\BPChem{H\_4C}\\
        \makecell{\BPChem{H\_2O\_2}\\unstable}&\BPChem{H\_4N\_2}&\BPChem{H\_6C\_2}\\
        not exists&\makecell{\BPChem{H\_5N\_3}\\unstable}&\BPChem{H\_8C\_3}\\
    \end{tabular}
\end{document}

Best Answer

The \rowcolors command needs 3 mandatory arguments. As I don't have bpchem installed, I loaded chemformula, which anyway has a simpler syntax for compounds. I took the liberty to change the shade of grey for a nicer one, and added some vertical padding at the top of rows:

\documentclass{article}
\usepackage{makecell}
\usepackage[table, svgnames]{xcolor}
\usepackage{chemformula}

\begin{document}

\begin{table}\setlength\extrarowheight{2pt}
 \rowcolors{1}{Lavender!80!gray}{white}
    \begin{tabular}{ccc}
    \ch{H2O}&\ch{H3N}&\ch{H4C}\\
        \makecell[t]{\ch{H2O2}\\unstable}&\ch{H4N2}&\ch{H6C2}\\
        not exists&\makecell[t]{\ch{H5N3}\\unstable}&\ch{H8C3}\\
    \end{tabular}
\end{table}

\end{document} 

enter image description here