Why is the start row of \rowcolors ignored in tabularx?

Seems like \rowcolors when used for a {tabluarx} doesn’t work properly: The specific number of the first row to be colored is ignored. This si not the case for a normal {tabluar}.

In both tables the coloring should start in the third row.

\documentclass{article}

\usepackage{tabularx}
\usepackage[table]{xcolor}

\begin{document}

\begin{minipage}{0.45\textwidth}
\verb|{tabularx}| \\[2ex]
\rowcolors{3}{blue!50}{yellow!60}
\begin{tabularx}{40mm}{X}
1 \\ 2 \\ 3 \\ 4 \\ 5 \\ 6 \\
\end{tabularx}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
\verb|{tabular}| \\[2ex]
\rowcolors{3}{blue!50}{yellow!60}
\begin{tabular}{p{40mm}}
1 \\ 2 \\ 3 \\ 4 \\ 5 \\ 6 \\
\end{tabular}
\end{minipage}

\end{document}

Is this a bug in xcolor/tabularx?

This question is kind of a follow-up question of my answer on Table cell with unwanted black background

• In case of tabularx it is a political act: an Ukrainian flag is added if first two rows. ;-) – Przemysław Scherwentke Mar 4 '16 at 19:04

Obviously tabularx doesn't have bugs, this is a documented feature.

TX sets the table several times, and restores latex counters but tex primitive counters can not be restored so easily. This defines a latex counter to shadow the \newcount allocated counter defined by xcolor.

\documentclass{article}

\usepackage{tabularx}
\usepackage[table]{xcolor}
\newcounter{tblerows}
\expandafter\let\csname c@tblerows\endcsname\rownum

\begin{document}

\begin{minipage}{0.45\textwidth}
\verb|{tabularx}| \\[2ex]
\rowcolors{3}{blue!50}{yellow!60}
\begin{tabularx}{40mm}{X}
1 \\ 2 \\ 3 \\ 4 \\ 5 \\ 6 \\
\end{tabularx}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
\verb|{tabular}| \\[2ex]
\rowcolors{3}{blue!50}{yellow!60}
\begin{tabular}{p{40mm}}
1 \\ 2 \\ 3 \\ 4 \\ 5 \\ 6 \\
\end{tabular}
\end{minipage}

\end{document}
• Thanks for your answer. But what do you mean by “documented”? Niether a search for rowcolor nor color (or color) shows result in the manual (that’s what I checkt before asking this question …). And how can you beside there are no bug (just asking for curiosity …) – Tobi Mar 4 '16 at 20:29
• @Tobi mostly it was a joke, it's my code so clearly I believe it's bug free. Actually the fact that plain tex counters are not restored isn't as documented as i remembered. it is documented that latex counters are restored. tabularx was written long before rowcolor (or even color package) existed so you wouldn't see anything specifically about that, although it's not really related to color just that the counter increases by 1 every row but is not reset so by the final setting it is already much bigger than 3 before the table starts. – David Carlisle Mar 4 '16 at 20:40
• I see :-) I wonder if the should be a “fix” for this non-bug in either of the packages since both are quite popular … – Tobi Mar 6 '16 at 9:37
• @David Carlisle Well this comment is not directly related to the question but rather to the code you have written. Why \makeatletter and \makeatother were not used when you defined the commands \expandafter\let\csname c@tblerows\endcsname\rownum as @ can be seen in that line? Are there special cases where \makeatletter and \makeatother are not necessary? – hesham Jan 28 at 12:33
• @hesham I just used csname there as an alternative I could have used \makeatletter then used \c@tblerows as if @ is a letter that parses as a singe csname, but if @ is a non-letter then ` \c@tblerows parses as \c @tblerows so would put a cedilla accent on an @... but you can still construct the token via \csname even with non-letters. – David Carlisle Jan 28 at 14:15