# Long table in landscape mode with alternating row colors does not work with \multicolumn

I am trying to put together a longtable in landscape mode over several pages using the longtable package.

The idea is simple. I want alternating row colors in the main body of the table. However, the main body is divided into sections. I want the rows separating sections in a different color (gray). When I try to do this it messes up the rowcolor scheme.

Attached a self-contained example. I commented out the problematic rows separating sections of the main body of the table. Uncomment them to see problem. I tried some suggestions in this Q&A to no help.

\documentclass{article}
% Packages for tables
% --------------------
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{longtable}
\usepackage[table]{xcolor}

% Blind text to fill space for typesetting
% ------------------------------------------
\usepackage[english]{babel}
\usepackage{blindtext}

% Set line spacing
% -----------------
\usepackage{setspace}
\doublespacing

\begin{document}

%Long landscape table
\begin{landscape}
\begin{center}
\begin{footnotesize}
\begin{singlespace}
\begin{longtable}{p{3.4in}p{4.6in}} %p{} fixes width of some columns
\caption[Overview of hypothesis test procedures]{\emph{Overview of hypothesis
test procedures}}  \label{tb:analysis}\\
\toprule
\hiderowcolors
\scshape Hypotheses & \scshape Test Procedure \\
\showrowcolors
\midrule

\multicolumn{2}{c}{{\bfseries \tablename\ \thetable{} -- continued from
previous page}}\\
\toprule
\hiderowcolors
\scshape Hypotheses & \scshape Test Procedure \\
\showrowcolors
\midrule

%Define first footer
\bottomrule
\multicolumn{2}{r}{{Continued on next page}} \\
\endfoot

%Define last footer
\bottomrule
\endlastfoot

%First problematic row commented out
%\multicolumn{2}{>{\columncolor[gray]{0.8}}l}{Primary Objective: Lore Ipsum}\\
\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\
\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\

\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\

\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\

\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\

\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\

\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\

\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\
%Second problematic row commented out
%   \multicolumn{2}{>{\columncolor[gray]{0.8}}l}{Secondary Objective: Differences
%   between x and y}\\

\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\

\multicolumn{2}{l}{\textbf{Awareness of pi}}\\
\blindtext
&
\blindtext. \\
\end{longtable}
\end{singlespace}
\end{footnotesize}
\end{center}
\end{landscape}
\end{document}

-

xcolor maintains a row counter and just checks whether it is even or odd. So if you want to insert an extra row without changing the effective parity you can just increment the counter in each of your extra rows:

  %Second problematic row commented out
%%%%%%%%%%%%%%%%%%%%%%%

-
Thank you! Worked like a charm. –  Fred Jul 2 '12 at 15:47