Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to put together a series of tables that show row reduction with simplex method (operations research concept). I'm trying to highlight the rows and columns used in simplex method, and these specific rows and columns change all the time. I've attempted the following:

\documentclass[12pt]{article}
\usepackage[margin=1cm,landscape,paperwidth=3in,paperheight=3in]{geometry}
\usepackage{amsmath,booktabs,colortbl}
\usepackage[table]{xcolor}
\pagestyle{empty}

\begin{document}
\newcolumntype{M}{>{$}c<{$}}
\newcolumntype{P}{>{\columncolor{gray!75}}M}
\rowcolors{2}{gray!25}{}
\begin{tabular}{|MPM|}
\hline
x_1 & y_1 & z_1 \\
x_2 & y_2 & z_2 \\
x_3 & y_3 & z_3 \\
x_4 & y_4 & z_4 \\
x_5 & y_5 & z_5 \\
x_6 & y_6 & z_6 \\
\hline
\end{tabular}
\end{document}

but it seems that each call to \rowcolor overrides the column color specified. Is there anyway to work around this behavior?

share|improve this question
    
There is some precedence set in terms of colour application. Using \cellcolor{gray!75} inside the affected cells (y_3 and y_5) overwrites what \rowcolors insert. –  Werner Nov 2 '12 at 16:11
    
Unfortunately, this particular TeX is being generated by a rather intensive script. At that point, it'd be easier to simply have every 'affected' cell be colored this way. –  Sean Allred Nov 2 '12 at 16:15
    
So it seems like you're after reversing the precedence here. That is, column colour should be written after the row colour (always)? –  Werner Nov 2 '12 at 16:19
    
That would actually work, I think. Post it as an answer and it'll have a good chance of being marked :D –  Sean Allred Nov 2 '12 at 16:22
add comment

1 Answer

up vote 3 down vote accepted

colortbl fairly arbitrarily gives row color precedence over column color, if you wish to reverse that decision you just need to change the order of \CT@column@color and \CT@row@color You can do this by applying a patch macro as below:

enter image description here

\documentclass[12pt]{article}
\usepackage[margin=1cm,landscape,paperwidth=3in,paperheight=3in]{geometry}
\usepackage{amsmath,booktabs,colortbl}
\usepackage[table]{xcolor}

\makeatletter
\def\tmpp#1\@addtopreamble#2#3!{%
    \tmp#2!{#1}{#3}}



\def\tmp#1\CT@column@color\CT@row@color#2!#3#4{%
\def\@classz{#3\@addtopreamble{#1\CT@row@color\CT@column@color#2}#4}}

\expandafter\tmpp\@classz!
\makeatother
\pagestyle{empty}

\begin{document}
\newcolumntype{M}{>{$}c<{$}}
\newcolumntype{P}{>{\columncolor{gray!75}}M}
\rowcolors{2}{gray!25}{}
\begin{tabular}{|MPM|}
\hline
x_1 & y_1 & z_1 \\
x_2 & y_2 & z_2 \\
x_3 & y_3 & z_3 \\
x_4 & y_4 & z_4 \\
x_5 & y_5 & z_5 \\
x_6 & y_6 & z_6 \\
\hline
\end{tabular}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.