2

I am working on a colored table and found clashes in various color packages and finally no color in alternate rows. I have followed suggestions, but nothing seems to be working fine. Below is my sample code.

\documentclass[11pt,a4paper]{article}
\usepackage{array,ragged2e}
\usepackage[pdftex]{graphicx}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage[margin=1cm]{geometry}
\usepackage{wrapfig}
\usepackage{comment}
\usepackage{parskip}
\usepackage{framed,color}
\usepackage{color}
\usepackage{colortbl}
\usepackage[table]{xcolor}

\definecolor{shadecolor}{rgb}{1,0.8,0.3}
\definecolor{lightgray}{rgb}{0.9}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
% new colours
\definecolor{shadecolor}{rgb}{1,0.8,0.3}
\definecolor{lightgray}{rgb}{0.9,0.9,0.9}
\definecolor{yellow}{rgb}{1,0.5,0}

\begin{document}

\begin{mdframed}[roundcorner=10pt,leftmargin=1, rightmargin=1, linecolor=orange,outerlinewidth=1, innerleftmargin=15, innertopmargin=15,innerbottommargin=15] 
\textbf{Detailed Test Table} 
\centering 
\rowcolors{1}{}{yellow}
\begin{tabular}{>{\rule{0pt}{.5cm}}c >{\arraybackslash}m{2cm}>{\arraybackslash}m{2cm}>{\arraybackslash}m{6cm} >{\arraybackslash}m{3cm}} 
\hline 

\rowcolor{orange}   \textbf{data} &\textbf{dummy} &\textbf{value} &\textbf{rough} &\textbf{text}\\ 
\hline 
\rowcolor{lightgray}        rsxx  & CreT  & 17603472, 19141561  & twet  & 17603472, 19141561\\ 
                     rs7193xx343  & TrT  & 19597491, 21760908  & twer  & 19597491, 21760908\\ 
                       rxx376333  & CCe  & 2017r3747  & twertw  & 20173747\\ 
\hline 
\end{tabular} 
\end{mdframed} 

\end{document}
manish
  • 9,111
  • 10
    Load only \usepackage[table]{xcolor} and remove the packages color,colortbl. Please load xcolor before mdframed. Additional you load color twice. – Marco Daniel Apr 23 '12 at 09:58

1 Answers1

11

Clashes come as the same package is loaded 2 or more times with different options that clash with each other. Here mdframed loads xcolor (due to tikz) but without table option. (mdframed also loads color). You are loading color two times which should be avoided. Also, your definition \definecolor{lightgray}{rgb}{0.9} is wrong. It should be \definecolor{lightgray}{rgb}{0.9,0.9,0.9} (which is again defined twice).

You can get rid of the clashes by one of these methods:

  • Use \PassOptionsToPackage{table}{xcolor} right before the \documentclass[11pt,a4paper]{article}.

  • Put \usepackage[table]{xcolor} before the package that loads xcolor (here it is mdframed)

  • Or pass the option to the document itself like \documentclass[11pt,a4paper,table]{article} and do not add \usepackage{xcolor} (It is already loaded by mdframed)

Here is a MWE that uses third method:

\documentclass[11pt,table,a4paper]{article}
%\usepackage[table]{xcolor}
\usepackage{array,ragged2e}
\usepackage{graphicx}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage[margin=1cm]{geometry}
\usepackage{wrapfig}
\usepackage{comment}
\usepackage{parskip}
\usepackage{framed}
%    
\definecolor{shadecolor}{rgb}{1,0.8,0.3}
%\definecolor{lightgray}{rgb}{0.9} % This definition is wrong should be {0.9,0.9,0.9}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
% new colours
\definecolor{shadecolor}{rgb}{1,0.8,0.3}
\definecolor{lightgray}{rgb}{0.9,0.9,0.9}
\definecolor{yellow}{rgb}{1,0.5,0}
%
\begin{document}
%
\begin{mdframed}[roundcorner=10pt,leftmargin=1, rightmargin=1, linecolor=orange,outerlinewidth=1, innerleftmargin=15, innertopmargin=15,innerbottommargin=15]
\textbf{Detailed Test Table}
\centering
\rowcolors{2}{lightgray}{yellow}
%\rowcolors[\hline]{3}{green!25}{yellow!50}
\begin{tabular}{>{\rule{0pt}{.5cm}}c >{\arraybackslash}m{2cm}>{\arraybackslash}m{2cm}>{\arraybackslash}m{6cm} >{\arraybackslash}m{3cm}}
\hline

\rowcolor{red}   \textbf{data} &\textbf{dummy} &\textbf{value} &\textbf{rough} &\textbf{text}\\
\hline
        rsxx  & CreT  & 17603472, 19141561  & twet  & 17603472, 19141561\\
                     rs7193xx343  & TrT  & 19597491, 21760908  & twer  & 19597491, 21760908\\
                       rxx376333  & CCe  & 2017r3747  & twertw  & 20173747\\
\hline
\end{tabular}
\end{mdframed}

\end{document}

enter image description here

Note: You may consider using booktabs to draw nice looking rules instead of \hrule. Also avoid passing the option pdftex to the package graphicx.

David Carlisle
  • 757,742