TransWikia.com

Remove white line in painted multirow tabular

TeX - LaTeX Asked by NickG on February 26, 2021

I have a table where the first row contains a multirow cell. The multi-row should be coloured gray.

Question 1

Unfortunately, a thin white line appears between the multirows (see the picture at the end). Here is the code:

begin{table}[H]
renewcommand{arraystretch}{1.5}
rowcolors{2}{white}{gray!25}
begin{center}
begin{tabular}{ | c | c | c | }
 arrayrulecolor{black} %changes color of hline
 hline
 rowcolor{gray!50} & {Max Power} & {Typ. Range}
 rowcolor{gray!50}multirow{-2}{*}{textbf{Class}} & (mW)  &  (m) 
 hline
 textbf{1} &  100 & 100
 textbf{2} & 2.5 & 10
 textbf{3} & 1 & 1
 textbf{4} & 0.5 & 0.5
 hline
end{tabular}
caption{Σύγκριση μεταξύ 2.4GHz και 5GHz}
end{center}
end{table}

Question2

Furthermore, I would like to adjust the spacing indicated with the red arrow. I would like it to be smaller, so that the text is closer to the line above, just for this specific row.

enter image description here

3 Answers

With column headers in thead command defined in the makecell package:

documentclass{article}

usepackage[table]{xcolor}
usepackage{array, makecell, multirow}
renewcommandtheadfont{normalsizebfseries}

usepackage{siunitx}


begin{document}
    begin{table}[ht]
    renewcommand{arraystretch}{1.5}
    %arrayrulecolor{black} %changes color of hline
    rowcolors{2}{white}{gray!25}
centering
begin{tabular}{ | >{bfseries}c | c | c | }
    hline
 rowcolor{gray!50} 
    & thead{Max Power (mW)} & thead{Typ. Range (m)}
    hline
1 &  100 & 100  
2 & 2.5  & 10   
3 & 1    & 1    
4 & 0.5  & 0.5  
    hline
end{tabular}
caption{Text in Greek language SI{2.4}{GHz} ... SI{5}{GHz}.}
    end{table}
end{document}   

enter image description here

Note: please, always provide an MWE, is the smallest complete document that reproduces the problem. It should contain all necessary packages and definitions required to run the example, but nothing more than that.

Correct answer by Zarko on February 26, 2021

The package nicematrix has tools to deal with that problem. With the following code, the thin white lines won't appear (they appear in some PDF viewers with the tools of colortbl, which is loaded by the option table of xcolor).

documentclass{article}

usepackage{nicematrix}

begin{document}

begin{table}
centering
renewcommand{arraystretch}{1.5}
begin{NiceTabular}{|>{bfseries}c|c|c|}%
  [
    code-before = rowcolors{2}{white}{gray!25}
                  rowcolor{gray!50}{1,2} 
  ]
 hline
 Block{2-1}{Class} & Max Power & Typ. Range[-3mm]
                    & (mW)  &  (m) 
 hline
 1 &  100 & 100
 2 & 2.5 & 10
 3 & 1 & 1
 4 & 0.5 & 0.5
 hline
end{NiceTabular}
end{table}

end{document}

However, you need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

Answered by F. Pantigny on February 26, 2021

I suggest to use makecell and its eponymous command. This way, you won't need multirow and the vertical spacing in the column heads will be shorter. (Note: I had to translate the caption text because I had troubles with my editor)

documentclass{article}
usepackage{caption, float, makecell}
usepackage[svgnames, table]{xcolor}

begin{document}

begin{table}[H]
renewcommand{arraystretch}{1.5}
rowcolors{2}{white}{gray!25}
begin{center}
begin{tabular}{ | c | c | c | }
 arrayrulecolor{black} %changes color of hline
 hline
 rowcolor{gray!50}textbf{Class} & makecell{Max Power (mW)} & makecell{Typ. Range(m)}
 hline
 textbf{1} & 100 & 100
 textbf{2} & 2.5 & 10
 textbf{3} & 1 & 1
 textbf{4} & 0.5 & 0.5
 hline
end{tabular}
caption{Comparison between 2.4GHz and 5GHz}
end{center}
end{table}

end{document}

enter image description here Edit: For the spacing problem, I suggest to delete the modification of arraystretch, to load the cellspace package and add these lines at the beginning of the table code (if you also load siunitx replace the letter S with the letter C):

setlength{cellspacetoplimit}{4pt}
setlength{cellspacebottomlimit}{4pt}
centering
begin{tabular}{|c|Sc|Sc|}

Answered by Bernard on February 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP