1

I'm coloring alternating groups (5 rows) in a table. I want to do this for the 40 data rows. I don't want to color the last row in the table that's a quality control checklist.

More or less I want to put a overall row limit on my coloring scheme. Below is compilable code to reproduce my output and I have attached an image of the current output with the last row incorrectly colored.

Output: enter image description here

Code:

\documentclass[letterpaper,11pt,oneside, notitlepage]{article}% calls document type
\usepackage[usenames, dvipsnames, table, xcdraw]{xcolor}
\usepackage{booktabs}% table utilities
\usepackage{siunitx}% number and symbol alignment
\usepackage{graphicx}
\usepackage{afterpage}
\pagenumbering{gobble}
\setlength\arrayrulewidth{0.7pt}
\newcommand\VRule[1][\arrayrulewidth]{\vrule width #1}

\makeatletter
\newcommand{\groupedRowColors}[5][-1]{% [#1: offset], #2: group size, #3: start line, #4: color 1, #5: color 2
    % copied from xcolor.sty
    \global\rownum=\z@
    \global\@rowcolorstrue
    \@ifxempty{#4}%
        {\def\@oddrowcolor{\@norowcolor}}%
        {\def\@oddrowcolor{\gdef\CT@row@color{\CT@color{#4}}}}%
    \@ifxempty{#5}%
        {\def\@evenrowcolor{\@norowcolor}}%
        {\def\@evenrowcolor{\gdef\CT@row@color{\CT@color{#5}}}}%
    % simplified (no check for \if@rowcmd)
    \def\@rowcolors{%
        \if@rowcolors
            \noalign{%
                \relax
                \ifnum\rownum<#3
                    \@norowcolor
                % I have changed this check:
                \else \ifodd \numexpr (\rownum-#1)/#2\relax
                    \@oddrowcolor
                \else
                    \@evenrowcolor
                \fi \fi
            }%
        \fi
    }%
    \CT@everycr{\@rowc@lors\the\everycr}%
    \ignorespaces
}
\makeatother

\usepackage[letterpaper,bindingoffset=-.35in,%
left=1in,right=1in,top=.25in,bottom=.25in,%
footskip=.15in]{geometry}

\begin{document}
\thispagestyle{empty}
\belowrulesep=0pt
\aboverulesep=0pt
\heavyrulewidth=2pt

\begin{table}[t!]
\begin{tabular}[l]{|p{.6in}|p{2.46in}|p{1in}|p{1.34in}| }
\toprule
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{}\\
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{\textbf{Date}\rule{.8in}{.1pt} \hspace{.69in} \textbf{Crew}\rule{2.4in}{.1pt}\hspace{.87in} \textbf{Page}\rule{.2in}{.1pt}  \textbf{of}\rule{.25in}{.1pt}}\\
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{}\\
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{\textbf{Species}\rule{.95in}{.1pt}\hfill \textbf{Location}\rule{.95in}{.1pt}\hfill \textbf{Project}\rule{.95in}{.1pt}}\\
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{}\\
\bottomrule
\end{tabular}
\end{table}

\vspace*{-2.75\baselineskip}
\begin{centering}
\begin{table}[bh!]
\groupedRowColors{5}{-1}{gray!15}{white}
\begin{tabular}{!{\VRule[2pt]}p{.6in}|p{1.5in}|p{.65in}|p{.65in}|p{2.6in}!{\VRule[2pt]}}
    \toprule
    \textbf{Count} & \textbf{Tag Number(s)} & \textbf{Start} & \textbf{End} & \textbf{Comments}\\
    \bottomrule
    & & & &\\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\

\toprule
\multicolumn{5}{!{\VRule[2pt]}l!{\VRule[2pt]}}{\textbf{Scanned}\rule{.6in}{.1pt}\hfill \textbf{Entered}\rule{.6in}{.1pt}\hfill \textbf{Checked}\rule{.6in}{.1pt}\hfill \textbf{Double Checked}\rule{.6in}{.1pt}}\\
\bottomrule
\end{tabular}
\end{table}
\end{centering}
\vspace*{-1\baselineskip}
\small\textit{\textbf{*} Max 40 Tests per sheet}\hspace{.5in}\textbf{Notes:}


\end{document}
1

A simple solution: adding a \rowcolor to your last row.

\documentclass[letterpaper,11pt,oneside, notitlepage]{article}% calls document type
\usepackage[usenames, dvipsnames, table, xcdraw]{xcolor}
\usepackage{booktabs}% table utilities
\usepackage{siunitx}% number and symbol alignment
\usepackage{graphicx}
\usepackage{afterpage}
\pagenumbering{gobble}
\setlength\arrayrulewidth{0.7pt}
\newcommand\VRule[1][\arrayrulewidth]{\vrule width #1}

\makeatletter
\newcommand{\groupedRowColors}[5][-1]{% [#1: offset], #2: group size, #3: start line, #4: color 1, #5: color 2
    % copied from xcolor.sty
    \global\rownum=\z@
    \global\@rowcolorstrue
    \@ifxempty{#4}%
        {\def\@oddrowcolor{\@norowcolor}}%
        {\def\@oddrowcolor{\gdef\CT@row@color{\CT@color{#4}}}}%
    \@ifxempty{#5}%
        {\def\@evenrowcolor{\@norowcolor}}%
        {\def\@evenrowcolor{\gdef\CT@row@color{\CT@color{#5}}}}%
    % simplified (no check for \if@rowcmd)
    \def\@rowcolors{%
        \if@rowcolors
            \noalign{%
                \relax
                \ifnum\rownum<#3
                    \@norowcolor
                % I have changed this check:
                \else \ifodd \numexpr (\rownum-#1)/#2\relax
                    \@oddrowcolor
                \else
                    \@evenrowcolor
                \fi \fi
            }%
        \fi
    }%
    \CT@everycr{\@rowc@lors\the\everycr}%
    \ignorespaces
}
\makeatother

\usepackage[letterpaper,bindingoffset=-.35in,%
left=1in,right=.9in,top=.25in,bottom=.25in,%
footskip=.15in]{geometry}

\begin{document}
\thispagestyle{empty}
\belowrulesep=0pt
\aboverulesep=0pt
\heavyrulewidth=2pt

\begin{table}[t!]
\begin{tabular}[l]{|p{.6in}|p{2.46in}|p{1in}|p{1.34in}| }
\toprule
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{}\\
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{\textbf{Date}\rule{.8in}{.1pt} \hspace{.69in} \textbf{Crew}\rule{2.4in}{.1pt}\hspace{.87in} \textbf{Page}\rule{.2in}{.1pt}  \textbf{of}\rule{.25in}{.1pt}}\\
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{}\\
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{\textbf{Species}\rule{.95in}{.1pt}\hfill \textbf{Location}\rule{.95in}{.1pt}\hfill \textbf{Project}\rule{.95in}{.1pt}}\\
\multicolumn{4}{!{\VRule[2pt]}l!{\VRule[2pt]}}{}\\
\bottomrule
\end{tabular}
\end{table}

\vspace*{-2.75\baselineskip}
\begin{centering}
\begin{table}[bh!]
\groupedRowColors{5}{-1}{gray!15}{white}
\begin{tabular}{!{\VRule[2pt]}p{.6in}|p{1.5in}|p{.65in}|p{.65in}|p{2.6in}!{\VRule[2pt]}}
    \toprule
    \textbf{Count} & \textbf{Tag Number(s)} & \textbf{Start} & \textbf{End} & \textbf{Comments}\\
    \bottomrule
    & & & &\\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\
    \hline
    & & & & \\

\toprule
\rowcolor{white} \multicolumn{5}{!{\VRule[2pt]}l!{\VRule[2pt]}}{\textbf{Scanned}\rule{.6in}{.1pt}\hfill \textbf{Entered}\rule{.6in}{.1pt}\hfill \textbf{Checked}\rule{.6in}{.1pt}\hfill \textbf{Double Checked}\rule{.6in}{.1pt}}\\
\bottomrule
\end{tabular}
\end{table}
\end{centering}
\vspace*{-1\baselineskip}
\small\textit{\textbf{*} Max 40 Tests per sheet}\hspace{.5in}\textbf{Notes:}


\end{document}

enter image description here

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.