0

I am trying to color every other grouping of 5 rows light gray, starting with the first 5 rows. I have attempted to use the solution posted here Does something like \rowcolors exist for groups of rows? . However, there are several problems. My original (uncolored; see below) looks great. However, when I try to color the rows (see below) the pdf looks terrible with missing rows and the printed version starts 1 row to late ( i.e., the first 5 line should be gray). So in summary I would like the pdf to look as nice as the printed and have the coloring start 1 row sooner. I have attached compilable code to reproduce the document and images of the output on my end below.

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}
\newcommand\VRule[1][\arrayrulewidth]{\vrule width #1}

\makeatletter
\newcommand{\groupedRowColors}[5][0]{% [#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{2.46in}| }
\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{1.2in} \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!20}{white} %<------line that is supposed to color by group
\begin{tabular}{!{\VRule[2pt]}p{.6in}|p{2.46in}|p{1in}|p{2.46in}!{\VRule[2pt]}}
    \toprule
    \textbf{Count} & \textbf{PIT Tag \#} & \textbf{Length(TL)} & \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{4}{!{\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 fish per sheet}\hspace{.5in}\textbf{Notes:}

\end{document}

This is what the original pdf looks like without coloring:

original data sheet

This is what it looks like after I apply the solution:

PDF

bad pdf

Printed bad printed

0

Here is the fixed code to solve the problem above:

This line fixes were row coloring starts

\groupedRowColors{5}{-1}{gray!15}{white}%<------- starts coloring at first row

This line makes is so row lines are visible in adobe reader

\setlength\arrayrulewidth{0.7pt}% <------- fixes so lines can be viewed in adobe reader

Full 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}
\setlength\arrayrulewidth{0.7pt}% <------- fixes so lines can be viewed in adobe reader
\newcommand\VRule[1][\arrayrulewidth]{\vrule width #1}

\makeatletter
\newcommand{\groupedRowColors}[5][0]{% [#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{2.46in}| }
\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{1.2in} \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}%<------- starts coloring at first row
\begin{tabular}{!{\VRule[2pt]}p{.6in}|p{2.46in}|p{1in}|p{2.46in}!{\VRule[2pt]}}
    \toprule
    \textbf{Count} & \textbf{PIT Tag \#} & \textbf{Length(TL)} & \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{4}{!{\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 fish per sheet}\hspace{.5in}\textbf{Notes:}
\end{document}

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.