横向模式下的长表与交替行颜色不兼容 \multicolumn

横向模式下的长表与交替行颜色不兼容 \multicolumn

longtable我正在尝试使用该包 将多页长表以横向模式组合在一起。

这个想法很简单。我想在表格主体中交替使用行颜色。但是,主体被分成了几个部分。我想让分隔各部分的行使用不同的颜色(灰色)。当我尝试这样做时,它会弄乱行颜色方案。

附上一个独立示例。我注释掉了表格主体各部分之间有问题的行。取消注释即可查看问题。我尝试了一些建议问答没有帮助。

\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}

答案1

xcolor维护一个行计数器,只检查它是偶数还是奇数。因此,如果您想插入一个额外的行而不更改有效奇偶校验,您只需在每个额外的行中增加计数器即可:

  %Second problematic row commented out
   \multicolumn{2}{>{\columncolor[gray]{0.8}}l}{\global\advance\rownum1 Secondar
                                                 %%%%%%%%%%%%%%%%%%%%%%%

相关内容