4

I would like a table where the background of the first line is gray and the background of the rest of the table is white. The problem is that the table has a double column line. I have tried \doublerulesepcolor but it allows me to put color between the two column lines for ALL the table and not for just the first line.

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

2 Answers 2

2

Er, sorry, this appears to be an undocumented feature.

Add this to the document preamble

\makeatletter
\let\old@mkpream\@mkpream
\def\@mkpream{%
\ifx\CT@drsc@\relax\else\let\CT@drsc@ @\fi
\let\CT@arc@\relax
\old@mkpream}
\makeatother

enter image description here

0

With {NiceTabular} of nicematrix, you have directly the expected output.

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

I have used the key colortbl-like in order to be able to use color the row with a command \rowcolor with a syntax similar to the syntax of the corresponding command of colortbl.

However, it's also possible to put the instructions for the color of the rows, columns and cells before the main array, in the \CodeBefore.

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .