7

I managed to get alternating row colours working when using tabular but when I converted them to tabulary to make the tables match \textwidth the row colouring became messed up.

Now it completely ignore the defined starting row and also changes the colour of the rows depending on the number of rows in the table. For example if there are an odd number of rows the top cell is grey, but when I add another row and make the number of rows even, the top cell becomes white. My code for such a table is below:

\documentclass{article}
\usepackage{tabulary}
\usepackage[table]{xcolor}
\definecolor{light-grey}{gray}{0.9}
%
\begin{document}
%
\begin{table}[h]
\rowcolors{2}{light-grey}{white}
\begin{tabulary}{\textwidth}{|l|L|}
\hline
\textbf{ID} & \textbf{Requirement} \\ \hline
REQ1      & Requirement 1 \\
REQ2      & Requirement 2 \\
\hline
\end{tabulary}
\caption{Functional Requirements}
\label{table:Functional Requirements}
\end{table}
%
\end{document}

Tenter image description herehis gives:

7

write into the preamble after loading tabulary:

\usepackage{etoolbox}
\preto\tabular{\global\rownum=0\relax}

This gives:

enter image description here

or without loading a package:

\let\Tabular\tabular
\def\tabular{\global\rownum=0\relax\Tabular}

It is a problem with all tabular packages which read its contents twice for calculating the width but does not reset the line counter.

  • Ahh that makes sense, also explains why my row counter started returning funny values too. Answer works perfectly, thank you! – Oli Walker Dec 9 '13 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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