3

After compiling (using pdflatex) the following

\documentclass[12pt]{amsart}
\usepackage{amsmath,amsthm,amssymb,amsxtra,amsopn}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{etoolbox}
\begin{document}
\begin{tabular}{|c|c|c|}
\hline
\rowcolor{lime!20}Item 1 & Item 2 & Item 3 \\
\hline
text & text & text\\
\hline
\end{tabular}
\end{document}

some of the borders of the table is invisible. After zooming in, the borders are visible. I observe this type of strange behaviour when dealing with such tables using \rowcolor or \cellcolor command. How to fix the code so that the borders of the output table are visible without zooming.

2 Answers2

5

Another option would be the new tabularray package (CTAN). It has the command \SetRow which you can use to modify all properties of the current row, including color. Using that, vertical lines appear correct with Adobe Acrobat Reader.

correct vertical lines

\documentclass[12pt]{amsart}
\usepackage{amsmath,amsthm,amssymb,amsxtra,amsopn}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{etoolbox}
\usepackage{tabularray}

\begin{document} rowcolor solution

\begin{tabular}{|c|c|c|}
    \hline
    \rowcolor{lime!20}Item 1 & Item 2 & Item 3 \\
    \hline
    text & text & text\\
    \hline
\end{tabular}
\vspace{1cm}

tabularray solution

\begin{tblr}{|c|c|c|}
    \hline
    \SetRow{lime!20} Item 1 & Item 2 & Item 3 \\
    \hline
    text & text & text\\
    \hline
\end{tblr}

\end{document}

Note: The package has different (better) default spacing, which you can modify with the rowsep and colsep keys as you like.

Edit: I don't exactly know what causes it, but the vertical and horizontal lines are the not all the same width for the colored cells with the colortbl solution. It seems as if the tabularray "encoding" is superior, since it does not cause any artifacts no matter the zoom level.

As Zarko pointed out in his comment, the tabularray package also supports a very nice key-value interface for formatting.

\begin{tblr}{
        hlines, vlines, cells = {c}, 
        row{1} = {bg=lime!20},
    }
    Item 1 & Item 2 & Item 3 \\ 
    text   & text   & text   \\     
\end{tblr}
marv
  • 2,099
  • 1
  • 7
  • 26
  • 1
    In my test table the widths of lines are equal in all rows. BTW, coorect code for tabularray is: `\documentclass[12pt]{amsart} \usepackage{xcolor} \usepackage{tabularray}

    \begin{document} \begin{tblr}{hlines, vlines, cells = {c}, row{1} = {bg=lime!20}} Item 1 & Item 2 & Item 3 \ text & text & text \ \end{tblr} \end{document}`. Anyway, +1 ;-)

    – Zarko Jan 06 '22 at 19:51
  • @Zarko I also prefer the key-value syntax :) However, I wanted to keep the answer as close to the original code to avoid additional confusion. – marv Jan 06 '22 at 20:31
  • @Zarko I have added the key-value formatting option to the answer now. – marv Jan 06 '22 at 20:43
2

You can use {NiceTabular} of nicematrix. Rules won't seem to disappear, whatever PDF viewer (and level of zoom) you use.

\documentclass[12pt]{amsart}
\usepackage[table]{xcolor}
\usepackage{nicematrix}

\begin{document}

With \verb|{tabular}| (and \verb|colortbl|).

\medskip \begin{tabular}{|c|c|c|} \hline \rowcolor{lime!20}Item 1 & Item 2 & Item 3 \ \hline text & text & text\ \hline \end{tabular}

\vspace{1cm}

With \verb|{NiceTabular}| of \verb|nicematrix|.

\medskip \begin{NiceTabular}{|c|c|c|}[colortbl-like] \hline \rowcolor{lime!20}Item 1 & Item 2 & Item 3 \ \hline text & text & text\ \hline \end{NiceTabular}

\end{document}

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

Output of the above code

F. Pantigny
  • 40,250
  • (+1). At coloring of tables the package nicematrix is superior to others. BTW, instead of \usepackage{xcolor}\usepackage{colortbl} I would write \usepackage[table]{xcolor} – Zarko Jan 06 '22 at 20:02
  • @Zarko: Good idea. I will modify. – F. Pantigny Jan 07 '22 at 12:46
  • @Zarko can you elaborate on this? Why is nicematrix superior to other packages such as say tabularray ? – marv Jan 07 '22 at 12:57
  • @marv, i mean regarding coloring cells and rows. No one of others handle this so good. In general in my list the tabularray is the first :-) – Zarko Jan 07 '22 at 13:27