# Color rows in table [closed]

How can I remove the small white line appears in the heading of this table?

My code is

    \documentclass{article}
\usepackage[table, dvipsnames]{xcolor}
\begin{document}
\begin{table}
\centering
\caption{Amount of exposure of default towards 3 counterparties}
{\centering (with netting and collateral agreement)\par}
\label{1}
\begin{tabular}{|c | c| c|}
\hline
\rowcolor{lightgray}
\rowcolor{lightgray}
& (with netting) & (no netting)\\
\hline
A & \$29,637,720 & \$92,604,560 \\
B & \$38,250,400 & \$107,949,900\\
C & \$124,619,600 & \$124,619,600 \\
\hline
Total&\$192,507,800 & \$325,174,100\\
\hline
\end{tabular}
\end{table}
\end{document}

• Please post a real full compilable code, not the image of a code fragment. – Bernard Jun 5 '17 at 19:47
• @Bernard OK I edit it – Duy Jun 5 '17 at 20:15
• I'm voting to close this question as off-topic because it is viewer and zoom-level dependent (output under SUMATRA at 125%; no lines visible; other zoom levels show lines or not). – Werner Jun 5 '17 at 21:34

A solution with makecell. I also improved the caption spacing w.r.t. to table (caption package) and added some vertical padding at the top and bottom of cells (cellspace package):

\documentclass{article}
\usepackage[table, svgnames, dvipsnames]{xcolor}
\usepackage{makecell, cellspace, caption}
\setlength\cellspacetoplimit{3pt}
\setlength\cellspacebottomlimit{3pt}
\begin{document}

\begin{table}
\centering\captionsetup{justification = centering}
\caption{Amount of exposure of default towards 3 counterparties\\ (with netting and collateral agreement)}
%{\centering}
\label{1}
\begin{tabular}{|Sc|Sc|Sc|}
\hline
\rowcolor{Gainsboro!60}
Counterparty & \makecell{Amount of EAD\\ (with netting)} & \makecell{Amount of EAD\\ (no netting)}\\
\hline
A & \phantom{1}\$\,29,637,720 & \phantom{1}\$\,92,604,560 \\
B & \phantom{1}\$\,38,250,400 & \$\,107,949,900\\
C & \$\,124,619,600 & \$\,124,619,600 \\
\hline
Total&\$\,192,507,800 & \$\,325,174,100\\
\hline
\end{tabular}
\end{table}

\end{document}


With the default vertical alignment of \makecell (centred), you obtain this, which looks nicer, in my opinion:

• Great. Very comprehensive solution – Duy Jun 5 '17 at 21:08

These kind of issues are mostly related to the PDF viewer, they will not appear in a print version of the document. One possible work-around, however, is to use just one row and use a tabular for the two-line cells. A new command \ccell can be quite handy for this.

\documentclass{article}
\usepackage[table, dvipsnames]{xcolor}
\begin{document}

\newcommand{\ccell}[1]{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}

\begin{table}
\centering
\caption{Amount of exposure of default towards 3 counterparties}
{\centering (with netting and collateral agreement)\par}
\label{1}
\begin{tabular}{|c|c|c|}
\hline
\rowcolor{lightgray}
Counterparty & \ccell{Amount of EAD\\(with netting)} & \ccell{Amount of EAD\\(no netting)} \\ \hline
A & \$29,637,720 & \$92,604,560      \\
B & \$38,250,400 & \$107,949,900     \\
C & \$124,619,600 & \$124,619,600    \\      \hline
Total&\$192,507,800 & \$325,174,100  \\      \hline
\end{tabular}
\end{table}

\end{document}


• It works. Very appreciate it. – Duy Jun 5 '17 at 20:42

I propose an alternate solution, following this one, which makes no use of vertical separators. I had to reduce by 1pt the vertical separation among columns and also the horizontal separation among the colored rows.

I used booktabs rules, and I used \addlinespace[0pt] to put the toprule exactly on the grey cells, without separation.

\documentclass{article}
\usepackage[table, dvipsnames]{xcolor}
\usepackage{array,booktabs}
\begin{document}
\begin{table}
\centering
\caption{Amount of exposure of default towards 3 counterparties}
{\centering (with netting and collateral agreement)}
\label{1}
\begin{tabular}{c!{\vrule width -1pt}c!{\vrule width -1pt}c}
\rowcolor{lightgray}
\rowcolor{lightgray}
& (with netting) & (no netting)\\[2pt]
A & \$29,637,720 & \$92,604,560 \\
B & \$38,250,400 & \$107,949,900\\
C & \$124,619,600 & \$124,619,600 \\
\midrule
Total&\$192,507,800 & \$325,174,100\\
\bottomrule
\end{tabular}
\end{table}
\end{document}


with this result:

Also, I feel you could totally avoid the top rule:

\documentclass{article}
\usepackage[table, dvipsnames]{xcolor}
\usepackage{array,booktabs}
\begin{document}
\begin{table}
\centering
\caption{Amount of exposure of default towards 3 counterparties}
{\centering (with netting and collateral agreement)}
\label{1}
\begin{tabular}{c!{\vrule width -1pt}c!{\vrule width -1pt}c}
\rowcolor{lightgray}
\rowcolor{lightgray}
& (with netting) & (no netting)\\[2pt]
A & \$29,637,720 & \$92,604,560 \\
B & \$38,250,400 & \$107,949,900\\
C & \$124,619,600 & \$124,619,600 \\
\midrule
Total&\$192,507,800 & \$325,174,100\\
\bottomrule
\end{tabular}
\end{table}
\end{document}


• It's better with no white strip! – Bernard Jun 5 '17 at 20:48
• @CarLaTeX I feel that the toprule has some whitespace around it. As you can see the second table is better, I don't think that the top rule serves much purpose anyway since the header is already highlighted – Moriambar Jun 6 '17 at 6:21
• @CarLaTeX Of course I will, but I'm at work now... – Moriambar Jun 6 '17 at 6:27
• @CarLaTeX better now? – Moriambar Jun 6 '17 at 16:43
• Much better now :) – CarLaTeX Jun 6 '17 at 16:59

Also with makecell and (off-topic) siunitx for S column type:

\documentclass{article}
\usepackage[table, svgnames, dvipsnames]{xcolor}
\usepackage{makecell}
\usepackage{caption}
\usepackage{siunitx}

\begin{document}
\begin{table}
\centering
\renewcommand\arraystretch{1.2}
\captionsetup{justification = centering}
\caption{Amount of exposure of default towards 3 counterparties\\ (with netting and collateral agreement)}
\label{1}
\begin{tabular}{|c|*{2}{>{\\,}S[table-format=9.0, group-separator={,}, table-align-text-pre=false, table-space-text-pre={\\,}
]|}
}
\hline
\rowcolor{Gainsboro!60}
Counterparty
\hline
A   &    29 637 720 &    92 604 560                     \\
B   &    38 250 400 &   107 949 900                     \\
C   &   124 619 600 &   124 619 600                     \\
\hline
Total
&   192 507 800 &   325 174 100                     \\
\hline
\end{tabular}
\end{table}
\end{document}


• (+1) Good idea to use siunitx. I was too tired to write it, and I did the alignment by hand, but yours is neater. – Bernard Jun 5 '17 at 22:04