3

I've created the following table:

\begin{table}[htb]
\centering
\begin{tabular}{cc|c|c|c|c|}
\cline{3-6}
&                                         
& \cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Col1 } 
& \cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Col2 } 
& \cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Col3 } 
& \cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} Col4 } 
\\ \hline
\rowcolor[HTML]{FFFFFF} 
\multicolumn{1}{|c|}
{\cellcolor[HTML]{3166FF}{\color[HTML]{FFFFFF} }}                       
& sub-row-1                   
& -                                                       
& -                                                        
& -                                                     
& -                                                              
\\ \cline{2-6} 
\rowcolor[HTML]{CEE3FF} 
\multicolumn{1}{|c|}
{\multirow{-2}{*}{\cellcolor[HTML]{3166FF}
{\color[HTML]{FFFFFF} row-1}}}  & 
{\color[HTML]{000000} sub-row-2} & 
{\color[HTML]{000000} -}                                & 
{\color[HTML]{000000} -}                                 & 
{\color[HTML]{000000} -}                              & 
{\color[HTML]{000000} -}                                       
\\ \hline

\end{tabular}
\caption{}
\label{}
\end{table}

As you can see from the picture below, when I compile the document in PDF, in the cell "row-1" there is a white row due to the merge of two cells.

image_table

How can i remove this line?

The command that I'm using to compile the document is:

pdflatex <document_name>

Thank you in advance

3 Answers 3

4

This line corresponds to the small gap creatd by the \cline{2-6}. A solution uses \hhline, which accepts \arrayrulecolor commands for each of its segments, so we can use a full width \hhline, which has the colour of the background in its first part. We have a very thin negative \vskip to make the white segment completely disappear.

I took the opportunity to simplify your code and added some \extrarowheight, so the cell contents is vertically centred:

\documentclass{article}
\usepackage{array, multirow}
\usepackage[table]{xcolor}
\definecolor{myblue}{HTML}{3166FF}
\usepackage{hhline} 

\begin{document}

\begin{table}[htb]
\centering\setlength{\extrarowheight}{2pt}
\begin{tabular}{cc|c|c|c|c|}
\hhline{~~|----}
\rowcolor{myblue}
\multicolumn{2}{c|}{\cellcolor{white}}
& \color{white} Col1 & \color{white} Col2 & \color{white} Col3 & \color{white} Col4 \\
\hline
\rowcolor{white}
\multicolumn{1}{|c|}
{\cellcolor{myblue}{\color{white}}}
& sub-row-1
& - & - & - & - \\[-0.1pt]
\hhline{|>{\arrayrulecolor{myblue}}->{\arrayrulecolor{black}}|-|-|-|-|-|}
\noalign{\vskip -0.1pt}
\rowcolor[HTML]{CEE3FF}
\multicolumn{1}{|c|}
{\multirow{-2}{*}{\cellcolor{myblue}%
{\color{white} row-1}}} &
sub-row-2 &
- & - & - & - \\
\hline
\end{tabular}
\caption{}
\label{}
\end{table}

\end{document} 

enter image description here

1
  • It works, thank you!
    – Giordano
    Commented Jun 29, 2020 at 13:21
5

With {NiceTabular} of nicematrix you have tools to color cells, rows and columns and you can draw all the expected rules with one key hvlines after having specified that there is a corner (corners=NW, NW standing for north west). You won't have artefacts in the PDF viewers.

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

\begin{document}    

\setlength{\extrarowheight}{4pt}

\begin{NiceTabular}{cccccc}[hvlines,corners=NW]
\CodeBefore
  \rowcolor[HTML]{CEE3FF}{3}
  \rowcolor[HTML]{3166FF}{1}
  \columncolor[HTML]{3166FF}{1}
\Body
  \RowStyle[color=white]{}
  & & Col1 & Col2 & Col3 & Col4 \\ 
  \Block{2-1}{\color{white} row-1}
  & sub-row-1 & - & - & - & - \\ 
  & sub-row-2 & - & - & - & - \\ 
\end{NiceTabular}

\end{document}

Output of the above code

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

0
3

For completeness of possible solutions ;-), with tabularray package:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{cells={c},
             hline{1} = {3-6}{solid},
             hline{2-Z} = {solid},
             row{1}={bg=cyan, fg=white},
             row{3}={bg=cyan!30},
             vline{1,2} = {2-3}{solid},
             vline{2-Z} = {solid}
             }
\SetCell[c=2]{c,white}
    &           & Col1  & Col2  & Col3  & Col4  \\
\SetCell[r=2]{c,m,bg=cyan, fg=white} row-1
    & sub-row-1 & --    & --    & --    & --    \\
    & sub-row-2 & --    & --    & --    & --    \\
\end{tblr}

\end{document}

enter image description here

You must log in to answer this question.

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