Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\definecolor{tableShade2}{HTML}{ECF3FE} % iTunes 

% 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}
\rowcolors{2}{tableShade2}{} 
\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}\\
  %Define first header
  \toprule
  \hiderowcolors
  \scshape Hypotheses & \scshape Test Procedure \\
  \showrowcolors
  \midrule
  \endfirsthead

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

  %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}
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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
   \multicolumn{2}{>{\columncolor[gray]{0.8}}l}{\global\advance\rownum1 Secondar
                                                 %%%%%%%%%%%%%%%%%%%%%%%
share|improve this answer
    
Thank you! Worked like a charm. –  Fred Jul 2 '12 at 15:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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