2

I'm having an issue with rowcolors from the xcolor package.

Whenever I use rowcolors before a table, it seems that the row counter does not reset with each tabularx environment.

I read that rowcolors uses the rownum counter internally, and I tried resetting this with \global\rownum=1, but unfortunately this does not seem to work.

I am basically just trying to alter all my tabularx environments to be colored:

\definecolor{table-shade}{gray}{0.9}
\let\oldtabularx\tabularx
\let\endoldtabularx\endtabularx
\renewenvironment{tabularx}{\table\rowcolors{1}{white}{table-shade}\oldtabularx}{\endoldtabularx\endtable}

I'd welcome any suggestions, and thanks for your help.

Brian
  • 111
  • 1
    have you seen Tables: Colouring odd/even mixed up it sounds quite similar... – cmhughes Apr 02 '13 at 00:03
  • 1
    Please provide a minimum working example (MWE) that generates the problem you're trying to solve. E.g., from your current description, I can't tell if you have two (or more) tabularx environments inside a table environment. – Mico Apr 02 '13 at 00:45
  • There are multiple tabularx environments but no table environments. – Brian Apr 02 '13 at 14:21
  • Neither the xpreto or preto commands mentioned in the other post seem to work. Thanks for pointing out this option though. – Brian Apr 02 '13 at 14:36
  • Brian, once again, seconding Mico: Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Speravir Apr 02 '13 at 15:33
  • Because no new answer is possible, this works for me even without etoolbox or xpatch (linebreaks disappear in comments): \usepackage[table]{xcolor} \definecolor{table-shade}{gray}{0.9} \usepackage{tabularx} \let\oldtabularx\tabularx \let\endoldtabularx\endtabularx \renewenvironment{tabularx}{\rowcolors{1}{white}{table-shade}\oldtabularx}{\endoldtabularx}. – Speravir Apr 02 '13 at 18:08

1 Answers1

0

As a workaround I just declared my own counter and used rowcolor or cellcolor with an if statement to achieve the desired results. I then reset my counter after each tabularx environment.

Brian
  • 111