我想要一个表格,其中第一行的背景是灰色,其余部分的背景是白色。问题是表格有双列线。我试过了,\doublerulesepcolor
但它允许我在两列线之间为所有表格添加颜色,而不仅仅是第一行。
\documentclass{report}
\usepackage{colortbl}
\begin{document}
\begin{verbatim}
\definecolor{Lightgray}{gray}{.80}
\doublerulesepcolor{Lightgray}
\begin{tabular}[t]{|c|c||c|}\hline
\rowcolor[gray]{.8} CityFrom & CityTo & Count\\\hline
\doublerulesepcolor{white}
a & c & 2\\
a & e & 1\\\hline
\end{tabular}
\end{verbatim}
\begin{center}
\definecolor{Lightgray}{gray}{.80}
\doublerulesepcolor{Lightgray}
\begin{tabular}[t]{|c|c||c|}\hline
\rowcolor[gray]{.8} CityFrom & CityTo & Count\\\hline
\doublerulesepcolor{white}
a & c & 2\\
a & e & 1\\\hline
\end{tabular}
\end{center}
While trying to solve the problem I realized that \verb+\arrayrulecolor+ can be changed at each line
but this not the case with \verb+\doublerulesepcolor+
\begin{verbatim}
\definecolor{Lightgray}{gray}{.80}
\setlength\arrayrulewidth{2pt}
\doublerulesepcolor{Lightgray}
\begin{tabular}[t]{|c|c||c|}\hline
\rowcolor[gray]{.8} CityFrom & CityTo & Count\\\hline
\arrayrulecolor{red}\doublerulesepcolor{red}
a & c & 2\\
\arrayrulecolor{blue}\doublerulesepcolor{blue}
a & e & 1\\\hline
\end{tabular}
\end{verbatim}
\begin{center}
\definecolor{Lightgray}{gray}{.80}
\setlength\arrayrulewidth{2pt}
\doublerulesepcolor{Lightgray}
\begin{tabular}[t]{|c|c||c|}\hline
\rowcolor[gray]{.8} CityFrom & CityTo & Count\\\hline
\arrayrulecolor{red}\doublerulesepcolor{red}
a & c & 2\\
\arrayrulecolor{blue}\doublerulesepcolor{blue}
a & e & 1\\\hline
\end{tabular}
\end{center}
What is needed is that \verb+\doublerulesepcolor+ has a ``local" behavior as \verb+\arrayrulecolor+.
Any hint how to obtain this ?
Regards
Esteban
\end{document}
答案1
呃,抱歉,这似乎是未记录的功能。
将此添加到文档序言中
\makeatletter
\let\old@mkpream\@mkpream
\def\@mkpream{%
\ifx\CT@drsc@\relax\else\let\CT@drsc@ @\fi
\let\CT@arc@\relax
\old@mkpream}
\makeatother
答案2
使用,您{NiceTabular}
可以nicematrix
直接获得预期的输出。
\documentclass{report}
\usepackage{nicematrix}
\begin{document}
\begin{center}
\begin{NiceTabular}{|c|c||c|}[colortbl-like]
\hline
\rowcolor[gray]{.8} CityFrom & CityTo & Count\\\hline
a & c & 2\\
a & e & 1\\\hline
\end{NiceTabular}
\end{center}
\end{document}
我已经使用了键,colortbl-like
以便能够使用具有与\rowcolor
相应命令的语法类似的语法的命令来为行着色colortbl
。
但是,也可以将行、列和单元格的颜色指令放在主数组之前的 中\CodeBefore
。