表格中行的颜色交替组(5)为灰色和白色

表格中行的颜色交替组(5)为灰色和白色

我试图将每 5 行的其余分组都涂成浅灰色,从前 5 行开始。我尝试使用此处发布的解决方案对于行组是否存在类似 \rowcolors 的东西? 。但是,有几个问题。我的原件(未着色;见下文)看起来很棒。但是,当我尝试为行着色(见下文)时,pdf 看起来很糟糕,缺少行,并且打印版本开始晚了 1 行(即,前 5 行应该是灰色)。所以总而言之,我希望 pdf 看起来和打印的一样好看,并且着色开始早 1 行。我已附上可编译代码以重现文档和下面我这边的输出图像。

代码

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

这是原始 PDF 在没有颜色的情况下的样子:

原始数据表

这是我应用解决方案后的样子:

PDF

坏的 pdf

打印 印刷不良

答案1

以下是解决上述问题的固定代码:

此行修复了行着色开始的问题

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

这一行使得行线在 Adob​​e Reader 中可见

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

完整代码:

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

相关内容