# \rowcolor and @{} issue

In the next example we can see that \rowcolor does not take into account the declaration @{} in tabular preambles.

Is this a normal behavior? Is there some elegant way to avoid that spurious filled space?

\documentclass{article}
\usepackage{xcolor, colortbl}

\begin{document}

\begin{tabular}{|c|c|c@{}|}
\rowcolor{gray!30}
text & text & text
\end{tabular}

\end{document}


\documentclass{article}
\usepackage{xcolor, colortbl}

\begin{document}

\begin{tabular}{|c|c|>{\kern-\tabcolsep}c<{\kern-\tabcolsep}|}
\rowcolor{gray!30}
text & text & text
\end{tabular}

\end{document}


The package nicematrix with its environment {NiceTabular} tries to solve the problems of the package colortbl.

Here is the output of {NiceTabular}.

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}
\begin{NiceTabular}{|c|c|c@{}|}[colortbl-like]
\Hline
\rowcolor{gray!30}
text & text & text\\
\Hline
\end{NiceTabular}
\end{document}


You need several compilations.

• +1 but I'm sure you meant "problems of the colortbl package users" and the package itself is problem and bug free, just with a couple of unexpected features:-) – David Carlisle Sep 15 '20 at 13:01
• @David Carlisle: You are right. Since I'm French, it's sometimes difficult to me to express exactly what I mean in English... – F. Pantigny Sep 15 '20 at 17:22
• sorry I was joking, your comment was perfectly correct. – David Carlisle Sep 15 '20 at 17:36
• Powerfull package! but I prefer not to use an external package just for this small issue. – e_moro Sep 15 '20 at 20:48

Do you looking for:

\documentclass{article}
\usepackage[table]{xcolor}

\begin{document}
\begin{tabular}{|c|c| >{\columncolor{white}[\tabcolsep][0pt]}c @{}|}
\rowcolor{gray!30}
text & text & text
\end{tabular}
\end{document}