# rowcolor doesn't fill complete cell

So I'm trying to color the rows in my table, but in the rows where I use \makecell, the colouring doesn't work properly. Somebody knows a solution for this?

\usepackage{xcolor, colortbl} %kleurtjes voor table
\definecolor{TopRow}{rgb}{0.4,0.7,1}
\definecolor{NormalRow}{rgb}{0.8,0.9,1}
\usepackage{makecell}

\begin{center}
\begin{tabular}{|l|l|l|}
\hline
\rowcolor{TopRow}
\textbf{Peptide Enrichtments} & \textbf{Hits} & \textbf{Found Genes} \\
\hline
\rowcolor{NormalRow}
Nothing &3 & \makecell[lt]{RAB5C \\ TNKS1BP1 \\ WDR43}\\
\hline
20X dilution& 1 & AHCY \\
\hline
\rowcolor{NormalRow}
TiO2& 2 & \makecell[lt]{TNKS1BP1\\ITPR2}\\
\hline
TiO2-3 &0& -\\
\hline
\rowcolor{NormalRow}
Fe-NTA & 0&- \\
\hline
\end{tabular}
\end{center}


EDIT:

So I did the following:

Nothing &3 & {\colorbox{NormalRow}{\makecell[lt]{RAB5C \\ TNKS1BP1 \\ WDR43}}}\\


But now the alignment is good anymore. anyone has solutions for that?

• Related: How to color column heads determined width makecell and Table cell line break, and rowcolors. Using colorbox around the makecell commands should yield the desired result. – leandriis Jun 11 '18 at 13:22
• Great, that works. Thank you. However now the words aren't left aligned anymore. Do you have a solution for that as well? Can I define the position of the colorbox? – Weronika Jun 11 '18 at 13:40
• You are right. I did not notice the slight shift of the text. In your case, I would suggest, that you drop the usage of makecell completely, as the layout in the table can also be achieved by using three separate rows for the first light blue row. This way you can continue using rowcolor. – leandriis Jun 11 '18 at 13:58

Instead of trying to make makecell and colortbl compatible, I'd suggest dropping the usage of makecell. You can achieve the same layout without it as shown in the following MWE:

\documentclass{article}

\usepackage[table]{xcolor}
\definecolor{TopRow}{rgb}{0.4,0.7,1}
\definecolor{NormalRow}{rgb}{0.8,0.9,1}

\begin{document}

\begin{tabular}{|l|l|l|}
\hline
\rowcolor{TopRow}
\textbf{Peptide Enrichtments} & \textbf{Hits} & \textbf{Found Genes} \\
\hline
\rowcolor{NormalRow}
Nothing & 3 & RAB5C \\
\rowcolor{NormalRow}
&   & TNKS1BP1 \\
\rowcolor{NormalRow}
&   & WDR43 \\
\hline
20X dilution& 1 & AHCY \\
\hline
\rowcolor{NormalRow}
TiO2 & 2 & TNKS1BP1\\
\rowcolor{NormalRow}
&   & ITPR2 \\
\hline
TiO2-3 &0& -\\
\hline
\rowcolor{NormalRow}
Fe-NTA & 0&- \\
\hline
\end{tabular}

\end{document}


As you use color as a structuring element in your table, you might also consider dropping all the horizonal and vertical rules. In the following example, I have also added a bit of extra vertical space:

\documentclass{article}

\usepackage[table]{xcolor}
\definecolor{TopRow}{rgb}{0.4,0.7,1}
\definecolor{NormalRow}{rgb}{0.8,0.9,1}

\begin{document}
\begingroup
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{lll}
\rowcolor{TopRow}
\textbf{Peptide Enrichtments} & \textbf{Hits} & \textbf{Found Genes} \\
\rowcolor{NormalRow}
Nothing & 3 & RAB5C \\
\rowcolor{NormalRow}
&   & TNKS1BP1 \\
\rowcolor{NormalRow}
&   & WDR43 \\
20X dilution& 1 & AHCY \\
\rowcolor{NormalRow}
TiO2 & 2 & TNKS1BP1\\
\rowcolor{NormalRow}
&   & ITPR2 \\
TiO2-3 &0& -\\
\rowcolor{NormalRow}
Fe-NTA & 0&- \\
\end{tabular}
\endgroup

\end{document}


This last example shows a more minimalistic approach without colors and bold text, but with white space and rules from the booktabs packages as structural elements:

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\begin{tabular}{lll}
\toprule
Peptide Enrichtments & Hits & Found Genes \\
\midrule
Nothing      & 3 & RAB5C    \\
&   & TNKS1BP1 \\