I'm trying to make a table with the following code:

  \rowcolor[gray]{.9} a & b & c \\

Unfortunately the \rowcolor command seems to not care about the empty leading and ending spaces in the table, i.e. the @{}'s in the tabular 'preamble'.

Any suggestions to overcome this issue are most welcome.

3 Answers 3


  \rowcolor[gray]{.9}[0pt][0pt] a & b & c \\\hline

enter image description here

  • Thank you for the solution! I actually ended up using: \newcolumntype{C}{c<{\kern\tabcolsep}<{\kern\tabcolsep}@{}} since it gave me the same distance between columns.
    – lysbjerg
    Nov 17, 2011 at 16:48
  • 3
    I think it would make more sense logically to define two new columns L and R (say) - for the left and right no-overhang columns - as \newcolumntype{L}{>{\hspace*{-\tabcolsep}}c} and \newcolumntype{R}{c<{\hspace*{-\tabcolsep}}} and use \begin{tabular}{L..R} without the additional \rowcolor options. That is, just \rowcolor[gray]{.9}.
    – Werner
    Nov 17, 2011 at 17:03
  • Works like a charm! And I even understand what the code does :-)
    – lysbjerg
    Nov 17, 2011 at 17:46

From the userguide of the colortbl package (which provides the commands \columncolor and \rowcolor):

\rowcolor takes the same argument forms as \columncolor. It must be used at the start of a row. If the optional overhang arguments are not used the overhangs will default to ... \tabcolsep ... [emphasis added]

Here, the length \tabcolsep is (half) the width of the intercolumn white space, and equals 6pt by default. However, specifying the \rowcolor command as

\rowcolor[gray]{.9}[][] % empty contents resolve to 0[pt]

will not produce what you're after either, I'm guessing, because this will leave white gaps in the table's two interior columns. The colortbl package doesprovides a \cellcolor command, but unfortunately this command doesn't take left- or right-hand trimming options, so you'd be back where you started out with.

In short, if you insist on using the \rowcolor command, you're probably best served by omitting the @{} specifiers at the far left and far right of the tabular specification.

  • Thank you for your suggestion. That fact that \tabcolsep equals half the width of the intercolumn white space helped me to modify Herbert's solution such that the intercolumn white space is unchanged.
    – lysbjerg
    Nov 17, 2011 at 16:52

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


\rowcolor[gray]{.9}a & b & c \\\hline


You do not need colortbl but you need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

You must log in to answer this question.

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