请问如何只为第一行和第二行之间的部分着色?
\documentclass[12pt,a4paper]{report}
\usepackage{multirow}
\usepackage{array}
\usepackage{longtable}
\usepackage{lscape}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.9}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\begin{longtable}{ *{9}{r}| *{6}{r} }
\hline
\rowcolor{Gray}
&&&&&&&&&&&&&&\\[-7pt]
\rowcolor{Gray}
\multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1}& \multicolumn{1}{c|}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} \\
\rowcolor{Gray}
\multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1}& \multicolumn{1}{c|}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} \\
\rowcolor{Gray} % <---------------- ??????????????????
&&&&&&&&&&&&&&\\[-7pt]
\hline
&&&&&&&&&&&&&&\\[-7pt]
\endhead
1&1&1&1&1&1&1&1&1&1&1&1&1&1&1 \\
\hline
\end{longtable}
\end{landscape}
\end{document}
答案1
代码中的问题在于使用 来&&&&&&&&&&&&&&\\[-7pt]
增加文本和水平线之间的距离。删除所有颜色,颜色显示在两条水平线之间。为了增加行高,我添加了包cellspace
。
\documentclass[12pt,a4paper]{report}
\usepackage{longtable}
\usepackage[table]{xcolor}
\definecolor{Gray}{gray}{0.9}
\usepackage{pdflscape}
\usepackage[column=0]{cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{\cellspacetoplimit}
\begin{document}
\begin{landscape}
\begin{longtable}{ *{9}{0r}| *{6}{0r} }
\hline
\rowcolor{Gray}
\multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1}& \multicolumn{1}{0c|}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} \\
\rowcolor{Gray}
\multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1}& \multicolumn{1}{0c|}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} & \multicolumn{1}{0c}{1} \\
\hline
\endhead
1&1&1&1&1&1&1&1&1&1&1&1&1&1&1 \\
\hline
\end{longtable}
\end{landscape}
\end{document}
以下是使用longtblr
from 的替代方法tabularray
:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\definecolor{Gray}{gray}{0.9}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\begin{longtblr}[caption = {caption},label = {key}]
{colspec = {*{9}{r}| *{6}{r}}, rowhead = 2, row{1,2}={c,Gray}}
\hline
1&1&1&1&1&1&1&1&1&1&1&1&1&1&1 \\
1&1&1&1&1&1&1&1&1&1&1&1&1&1&1 \\ \hline
1&1&1&1&1&1&1&1&1&1&1&1&1&1&1 \\ \hline
\end{longtblr}
\end{landscape}
\end{document}