6
\documentclass[11pt]{article}
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.9}
\begin{document}
\begin{table}[ht]
\caption{default}
\begin{center}
\rowcolors{1}{}{lightgray}
\begin{tabular}{r|rrrrr}
  \hline
 & 1 & 2 & 3 & 4 & 5 \\
  \hline
1 & 2.36 & 1.08 & -0.49 & -0.82 & -0.65 \\
  2 & -0.68 & -1.13 & -0.42 & -0.72 & 1.51 \\
  3 & -1.00 & 0.02 & -0.54 & 0.31 & 1.28 \\
  4 & -0.99 & -0.54 & 0.97 & -1.12 & 0.59 \\
  5 & -2.35 & -0.29 & -0.53 & 0.30 & -0.30 \\
  6 & -0.10 & 0.06 & -0.85 & 0.10 & -0.60 \\
  7 & 1.28 & -0.46 & 1.33 & -0.66 & -1.80 \\
  8 & 0.80 & 0.46 & 1.37 & 1.73 & 1.93 \\
  9 & -0.75 & 0.28 & 0.51 & 0.19 & 0.58 \\
  10 & -1.64 & -0.12 & -1.17 & -0.10 & -0.04 \\
   \hline
\end{tabular}
\end{center}
\end{table}
\end{document}

faintly colors vertical lines too, how to avoid?: enter image description here

curious
  • 193
  • Hi, can you see if this question and the @Bernard 's answer is it fine for you :-)?https://tex.stackexchange.com/questions/300994/eliminating-little-white-vertical-lines-in-tabular-caused-by-colortbl-colorcell To me seem a duplicate your question. – Sebastiano Jun 16 '21 at 14:35

2 Answers2

4

I think that what you see is mostly aliasing and/or effect of the viewer antialiasing algorithms. Your code, using okular, 1600% magnification, color picked:

enter image description here

enter image description here

If the effect annoys you, you can remove all the vertical lines and play with spaces and styles:

enter image description here

\documentclass[11pt]{article}
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.9}
\usepackage{booktabs}
\begin{document}
\begin{table}[ht]
\caption{default}
\begin{center}
\rowcolors{1}{}{lightgray}
\begin{tabular}{>{\bfseries}rrrrrr}
  \toprule
  \qquad & 1 & 2 & 3 & 4 & 5 \\
  \midrule
  1 & 2.36 & 1.08 & -0.49 & -0.82 & -0.65 \\
  2 & -0.68 & -1.13 & -0.42 & -0.72 & 1.51 \\
  3 & -1.00 & 0.02 & -0.54 & 0.31 & 1.28 \\
  4 & -0.99 & -0.54 & 0.97 & -1.12 & 0.59 \\
  5 & -2.35 & -0.29 & -0.53 & 0.30 & -0.30 \\
  6 & -0.10 & 0.06 & -0.85 & 0.10 & -0.60 \\
  7 & 1.28 & -0.46 & 1.33 & -0.66 & -1.80 \\
  8 & 0.80 & 0.46 & 1.37 & 1.73 & 1.93 \\
  9 & -0.75 & 0.28 & 0.51 & 0.19 & 0.58 \\
  10 & -1.64 & -0.12 & -1.17 & -0.10 & -0.04 \\
   \bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}
Rmano
  • 40,848
  • 3
  • 64
  • 125
  • Impressive answer :-) – Sebastiano Jun 16 '21 at 14:53
  • 2
    Well, I teach analog electronics, and aliasing is one of my pet-peeves. If you only knew the number of papers I reviewed getting it wrong... – Rmano Jun 16 '21 at 14:54
  • ok I see the lines fluctuate as I zoom. So I guess this is nothing I can fix in my doc, just an artifact of viewing? – curious Jun 16 '21 at 14:55
  • @curious exactly. In addition, there can be also an effect of vision here: https://slate.com/technology/2013/12/optical-illusion-shades-of-gray.html – Rmano Jun 16 '21 at 14:57
4

The package nicematrix has tools specifically designed to solve that kind of problems.

The environment {NiceTabular} draws the colored cells, rows and columns before the rules. The resulting PDF is much easier to interpret by the PDF viewers and you won't have the effect you see by using the package colortbl (which is loaded by the key table of xcolor).

\documentclass[11pt]{article}
\usepackage{xcolor}
\definecolor{lightgray}{gray}{0.9}
\usepackage{nicematrix}

\begin{document} \begin{table}[ht] \caption{default}

\begin{center}

\begin{NiceTabular}{r|rrrrr} \CodeBefore \rowcolors{1}{}{lightgray} \Body \hline & 1 & 2 & 3 & 4 & 5 \ \hline 1 & 2.36 & 1.08 & -0.49 & -0.82 & -0.65 \ 2 & -0.68 & -1.13 & -0.42 & -0.72 & 1.51 \ 3 & -1.00 & 0.02 & -0.54 & 0.31 & 1.28 \ 4 & -0.99 & -0.54 & 0.97 & -1.12 & 0.59 \ 5 & -2.35 & -0.29 & -0.53 & 0.30 & -0.30 \ 6 & -0.10 & 0.06 & -0.85 & 0.10 & -0.60 \ 7 & 1.28 & -0.46 & 1.33 & -0.66 & -1.80 \ 8 & 0.80 & 0.46 & 1.37 & 1.73 & 1.93 \ 9 & -0.75 & 0.28 & 0.51 & 0.19 & 0.58 \ 10 & -1.64 & -0.12 & -1.17 & -0.10 & -0.04 \ \hline \end{NiceTabular} \end{center}

\end{table} \end{document}

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

Output of the above code

F. Pantigny
  • 40,250