1

I'm trying to make a table with the first column and row as colored, but the rest of the cells in white. Though it works almost as expected, there's a thin white line between some cells that should be merged I'd love to get help removing them.

Here's the code I have so far:

\documentclass[10pt]{iopart}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{hhline}
\begin{document}
\begin{table*}
    \begin{tabular}{p{3cm}p{5.25cm}p{5.25cm}}
        \rowcolor{black}
      &\multicolumn{1}{c}{\textbf{\color{white}Title A}} & \multicolumn{1}{c}
      {\textbf{\color{white}Title B}} \\  
         
        \cellcolor{black}\textbf{\color{white}Foo A }
            &   X
            &   Y \\ \hhline{~--}   
        
        \cellcolor{black} & X & Y\\
        \cellcolor{black}& X& Y\\
        \multirow{-3}{*}{\cellcolor{black}\color{white}Foo B}& X& Y\\ \hhline{~--} 

        \cellcolor{black}\textbf{\color{white}Foo C} 
            &   X 
            &   Y\\
        \cellcolor{black}
         &  &   Y \\
        \cellcolor{black}
         &  &   Y \\
    \end{tabular}
    \caption{Caption.}
\end{table*}
\end{document}

It looks like this: A table with a thin white line between cells in the first column that are blank

Foo A (Row 2) needs no changing.

Foo C (Rows 6-8) I want to get rid of the white spacing connecting the three rows.

Foo B (Rows 3-5) was my attempt at using a solution I found in this similar question I thought might help by using multirows. Apart from not removing the white line between the cells, it also centers the "Foo B" text vertically, which I don't want.

Ideally, I would like the result to look like this (but with Foo B at the top of its rows): A table without a thin white line between cells in the first column that are blank

Thanks!

2
  • 1
    the colortbl package explicitly documents that it is incompatible with \cline. You could use hhline to draw the rules or use a more modern package such as tabularray which uses different mechanisms to colour the cells. Commented Feb 3, 2022 at 20:16
  • Sure, switched to hhline, the problem remains the same though? Commented Feb 3, 2022 at 22:34

2 Answers 2

2

Package tabularray makes better tables with clean code:

\documentclass[10pt]{article}

\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\begin{table*}
  \begin{tblr}{
    colspec = {p{3cm}p{5.25cm}p{5.25cm}},
    row{1} = {bg=gray2,fg=white,c},
    column{1} = {bg=gray2,fg=white,font=\bfseries},
  }   
                           & Title A & Title B \\          
                     Foo A & X       & Y       \\\hline
    \SetCell[r=3]{h} Foo B & X       & Y       \\ 
                           & X       & Y       \\
                           & X       & Y       \\\hline
    \SetCell[r=3]{h} Foo C & X       & Y       \\
                           & X       & Y       \\
                           & X       & Y       \\\hline
  \end{tblr}
  \caption{Caption}
\end{table*}

\end{document}

Inside \SetCell command, r=3 is for mulitrow, and h is for vertical alignment.

enter image description here

8
1

Here is a code with the classical package colortbl (loaded by the key table of the package xcolor) which gives a good output.

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

\begin{document}

\arrayrulecolor{orange}

\begin{table*}

\sffamily

\begin{tabular}{>{\columncolor{black}\color{white}}w{l}{3cm}w{l}{5.25cm}w{l}{5.25cm}}
    \rowcolor{black}
          & \multicolumn{1}{c}{\color{white}Title A} & \multicolumn{1}{c}{\color{white}Title B} \\
    Foo A & X & Y \\ \cline{2-3}
    Foo B & X & Y \\
          & X & Y \\
          & X & Y \\ \cline{2-3}
    Foo C & X & Y \\
          &   & Y \\
          &   & Y \\
\end{tabular}
\caption{Caption.}

\end{table*}

\end{document}

Output of the first code

However, there are some thin white lines in the black panels (it depends of the PDF viewer: with PDF.js, used for instance by Firefox, they are usually present).

The package nicematrix has tools to address that problem.

Form the previous code, I will now:

  • load nicematrix (and unload colortbl);
  • replace {tabular} by {NiceTabular};
  • add the key color-inside (alias: colortbl-like) to say that there are instructions of color in the array itself (and not in so-called \CodeBefore provided by nicematrix).
\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}

\arrayrulecolor{orange}

\begin{table*}

\sffamily

\begin{NiceTabular}{>{\columncolor{black}\color{white}}w{l}{3cm}w{l}{5.25cm}w{l}{5.25cm}}[color-inside]
    \rowcolor{black}
          & \multicolumn{1}{c}{\color{white}Title A} & \multicolumn{1}{c}{\color{white}Title B} \\
    Foo A & X & Y \\ \cline{2-3}
    Foo B & X & Y \\
          & X & Y \\
          & X & Y \\ \cline{2-3}
    Foo C & X & Y \\
          &   & Y \\
          &   & Y \\
\end{NiceTabular}
\caption{Caption.}

\end{table*}

\end{document}

Here is the output (once again copied from Firefox).

Output of the above

You must log in to answer this question.

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