# [Tex/LaTex] Why is the start row of \rowcolors ignored in tabularx

colorrowcolortablestabularx

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

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

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}