2

I used cellcolor to change the color of a cell in the table. But, for some strange reason, it doesnot color it completely. Why would that happen? Below is MWE:

\documentclass[twoside,b5paper,9.5pt,openright]{book}
\usepackage[total={13cm,19.5cm}]{geometry} 
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{tocloft}
\usepackage{fixltx2e}
\usepackage{graphicx}           % include graphs/ figures  in the file
\usepackage{setspace}           % to set the line spacing in the document
\usepackage{ragged2e}
\usepackage{lscape}             % to write pages in landscape environment
\usepackage{array,threeparttable}       % to add footnotes to the tables
\usepackage{booktabs}
\usepackage{caption}    % to create some space between table caption and table, otherwise there was no space
\captionsetup[figure]{font=small,skip=0pt}
\captionsetup[table]{font=small,skip=0pt}
\usepackage[normalem]{ulem}     % to underline the text
\setcounter{secnumdepth}{3}
\usepackage{multirow}
\usepackage[labelfont=bf]{caption}
\let\newfloat\relax
\usepackage{floatrow}
\usepackage{array,threeparttable,siunitx}
\floatsetup[table]{capposition=top}
\floatsetup[figure]{capposition=bottom}
\usepackage{etoolbox}
\usepackage{subfig}
\usepackage[table]{xcolor}
\usepackage{grffile}            % to avoid printing the figure name (or otherwise, give figure names without spaces)
\usepackage{float}              % figures as 6 (a), 6 (b) etc.
\usepackage{tabu}
\usepackage{tikz}
\usepackage{arydshln}
\raggedbottom
%\allsectionsfont{\sf

\begin{document}

\begin{table}[h!]
\scriptsize
  \centering
  \caption{Free  (mg/100g ter) and aride compos (gy maer) in pokuls}
    \begin{tabular}{p{3cm}p{1.75cm}p{1.75cm}p{1.75cm}p{1.75cm}}
    \toprule
    \textbf{\cellcolor{blue!25}Frtion (matter)} & \multicolumn{1}{c}{\cellcolor{blue!25}\textbf{M\textsubscript{0}}} & \multicolumn{1}{c}{\cellcolor{blue!25}\textbf{M\textsubscript{15}}} & \multicolumn{1}{c}{\cellcolor{blue!25}\textbf{M\textsubscript{60}}} & \multicolumn{1}{c}{\cellcolor{blue!25}\textbf{M\textsubscript{120}}}\tabularnewline  
    \midrule
    \textit{Esseo acids} &       &       &       &  \tabularnewline     \addlinespace
    Valine & \multicolumn{1}{c}{75} & \multicolumn{1}{c}{40} & \multicolumn{1}{c}{26} & \multicolumn{1}{c}{10} \tabularnewline      \addlinespace
        \textit{\textbf{Total }} & \multicolumn{1}{c}{\textbf{11.84}} & \multicolumn{1}{c}{\textbf{10.24}} & \multicolumn{1}{c}{\textbf{9.2}} & \multicolumn{1}{c}{\textbf{10.18}} \tabularnewline      
    \bottomrule
    \end{tabular}%
   \end{table}%    

   \end{document}
  • Thank you for posting a working example! At the same time, much of your code does not seem to be relevant to the question you're asking here. Please limit the example to only the code required for your issue to appear. You can have a look at this guide for how to prune your code for this purpose. – LaRiFaRi Mar 24 '15 at 22:45
  • @Werner If I try it by taking it out from \textbf{}, it still gives the same solution. – abhishek Mar 24 '15 at 22:50
2

\cellcolor should be the first thing that appears in the cell, except when using \multicolumn. Below I've also provided an updated \toprulec and \midrulec which inserts a coloured separation using \specialrules to make the heading more uniform:

enter image description here

\documentclass{article}
\usepackage{booktabs,fixltx2e}
\usepackage[table]{xcolor}

\newcommand{\toprulec}{% Coloured \toprule
  \arrayrulecolor{black}\specialrule{\heavyrulewidth}{\aboverulesep}{0pt}
  \arrayrulecolor{blue!25}\specialrule{\belowrulesep}{0pt}{0pt}
  \arrayrulecolor{black}
}
\newcommand{\midrulec}{% Coloured \midrule
  \arrayrulecolor{blue!25}\specialrule{\aboverulesep}{0pt}{0pt}
  \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{\belowrulesep}
}
\begin{document}

\begin{tabular}{p{3cm}p{1.75cm}p{1.75cm}p{1.75cm}p{1.75cm}}
  \toprulec
  \cellcolor{blue!25}\textbf{Frtion (matter)} & 
    \multicolumn{1}{c}{\cellcolor{blue!25}\textbf{M\textsubscript{0}}} & 
    \multicolumn{1}{c}{\cellcolor{blue!25}\textbf{M\textsubscript{15}}} & 
    \multicolumn{1}{c}{\cellcolor{blue!25}\textbf{M\textsubscript{60}}} & 
    \multicolumn{1}{c}{\cellcolor{blue!25}\textbf{M\textsubscript{120}}} \\
  \midrulec
  \textit{Esseo acids} &       &       &       &  \\
  \addlinespace
  Valine & \multicolumn{1}{c}{75} & \multicolumn{1}{c}{40} & \multicolumn{1}{c}{26} & \multicolumn{1}{c}{10} \\
  \addlinespace
  \textit{\textbf{Total }} & 
    \multicolumn{1}{c}{\textbf{11.84}} & 
    \multicolumn{1}{c}{\textbf{10.24}} & 
    \multicolumn{1}{c}{\textbf{9.2}} & 
    \multicolumn{1}{c}{\textbf{10.18}} \\     
  \bottomrule
\end{tabular}

\end{document}

Similarly, \rowcolor should be the first thing that appears in the row.

  • I get the same solution, but what I mean is that the cell that is now colored blue, is not completely blue. I see 1mm on the top and 1mm on the bottom that is uncolored. Can this be fixed? – abhishek Mar 24 '15 at 22:51
  • @abhishek: See the updated answer. – Werner Mar 24 '15 at 23:00
  • Seems it like works. but if I have this table in a chapter in a thesis, where should I place this rule? in the main preamble? or close to the table - locally in a chapter? – abhishek Mar 24 '15 at 23:05
  • 1
    Place the \specialrule definitions in your preamble and then you can use them anywhere in your document. – Werner Mar 24 '15 at 23:07
  • Works very well!!! Thanks a lot.. Have to submit my thesis this week! – abhishek Mar 24 '15 at 23:11

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.