6

The MWE below shows that the \cellcolor command doesn't properly fill a table cell in revtex4-1 where it would do so in a simple article. Can anyone help me get fills that extend to the boundaries of my cells in revtex4-1?

Difference between article and revtex colortbl

\documentclass{revtex4-1}
\usepackage{colortbl}
\begin{document}
\begin{tabular}{ |c|l|l| } \hline
\rowcolor{red} A    & B     & C     \\ \hline
Hello World         & other     & \cellcolor{blue}stuff\\ \hline
\end{tabular}
\end{document}
sven
  • 303

2 Answers2

5

enter image description here

revtex inserts some extra \tabcolsep spaces and so add three lines to compensate:

\documentclass{revtex4-1}
\usepackage{colortbl}

\makeatletter

    \def\CT@@do@color{%
      \global\let\CT@do@color\relax
            \@tempdima\wd\z@
            \advance\@tempdima\@tempdimb
            \advance\@tempdima\@tempdimc
    \advance\@tempdimb\tabcolsep
    \advance\@tempdimc\tabcolsep
    \advance\@tempdima2\tabcolsep
            \kern-\@tempdimb
            \leaders\vrule
    %^^A                     \@height\p@\@depth\p@
                    \hskip\@tempdima\@plus  1fill
            \kern-\@tempdimc
            \hskip-\wd\z@ \@plus -1fill }
    \makeatother
    \begin{document}

    \begin{tabular}{ |c|l|l| } \hline
    \rowcolor{red} A    & B     & C     \\ \hline
    Hello World         & other     & \cellcolor{blue}stuff\\ \hline
    \end{tabular}
    \end{document}
David Carlisle
  • 757,742
  • Well played David, first prize to you. I'm gonna resign myself to the fact that these little tweaks will be out of my reach for quite some time. – sven Mar 15 '13 at 17:45
  • 4
    @sven such tweaks are easier if you've written the package and had something to do with the class that's in conflict. – David Carlisle Mar 15 '13 at 18:31
  • This solution doesn't work if you wrap up the tabular environment into ruledtabular one that adds nice starting and opening double horizontal bars. –  Aug 22 '13 at 14:19
1

The problem is still present with the class revtex4.2 (v. 4.2e).

With the environment {NiceTabular} of nicematrix (similar to {tabular} of array), you have directly the output you want. In fact, the output is better than with the class article because the rules won't seem to vanish in some PDF viewers at some levels of zoom (as in the picture of the OP).

 \documentclass{revtex4-2}
 \usepackage{nicematrix}
 \begin{document}
 \begin{NiceTabular}{ |c|l|l| }[colortbl-like] \hline
 \rowcolor{red} A    & B     & C     \\ \hline
 Hello World         & other     & \cellcolor{blue}stuff\\ \hline
 \end{NiceTabular}
 \end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

F. Pantigny
  • 40,250