3

after I add color to table, it has some problem for dispalying, here is the sample code:

\documentclass{article}

\usepackage{xcolor,colortbl}
\definecolor{Gray}{gray}{0.85}

\begin{document}
test a color table:
\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\rowcolor{Gray}
Version & Date & Author & Reason of Change \\
\hline 
0.1 & \today & Chen How & create initial documentation template, all content are dummy \\
\hline 
 & & & \\
\hline 
 & & & \\
\hline 
\end{tabular}
\end{center}
\caption{Document history}
\end{table}
\end{document}

The problem shows when I read it by pdf: enter image description here the line also changed when I zoom in and zoom out, but w/o color, it always OK: enter image description here

This is normal behavior or my problem?

How Chen
  • 733

2 Answers2

4

You can redraw the line after the tabular e.g. with tikz (in the example in red). An alternative is to draw the gray background before the tabular (also with tikz). See e.g. Background colour for cells with padding

\documentclass{article}

\usepackage[table]{xcolor}
\definecolor{Gray}{gray}{0.85}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
test a color table:
\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\rowcolor{Gray}
Version & \multicolumn{1}{c!{\tikzmark{x}\vrule}}{Date} & Author& Reason of Change \\
\hline
0.1 & \today & Chen How & create initial documentation template, all content are dummy \\
\hline
 & & & \\
\hline
 & & & \\
\hline
\end{tabular}%
\tikz[overlay,remember picture]\draw[line width=\arrayrulewidth,red]([xshift=0.5\arrayrulewidth,yshift=-\dp\strutbox]pic cs:x)--++(0,\baselineskip);
\end{center}
\caption{Document history}
\end{table}
\end{document}

But depending on the struktur of your tabular it can take quite some fiddling.

enter image description here

Ulrike Fischer
  • 327,261
2

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

The environment {NiceTabular} is similar to {tabular} (of array) but provides (when the key color-inside, alias colortbl-like is used) tools to color the cells, row and columns with a syntax similar to the syntax of colortbl. It does not use colortbl.

You have a good result in all the PDF viewers (you don't have rules which seem to vanish at some levels of zoom; you don't have the thin white lines you see for instance in the viewers using MuPDF such as SumatraPDF when the tabular is constructed with colortbl).

However, you need several compilations.

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}
\definecolor{Gray}{gray}{0.85}
\begin{document}
test a color table:
\begin{table}[h]
\begin{center}
\begin{NiceTabular}{|c|c|c|c|}[color-inside]
\hline
\rowcolor{Gray}Version & Date & Author & Reason of Change \\
\hline
0.1 & \today & Chen How & dummy content \\
\hline
 & & & \\
\hline
 & & & \\
\hline
\end{NiceTabular}
\end{center}
\caption{Document history}
\end{table}
\end{document}

Ouput of the above code

In fact, with {NiceTabular}, it's possible to draw all the rules with only one key hvlines. It's also possible to give the instructions for the colors before the body of the array in the "\CodeBefore".

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}
\definecolor{Gray}{gray}{0.85}
\begin{document}
test a color table:
\begin{table}[h]
\begin{center}
\begin{NiceTabular}{cccc}[hvlines]
\CodeBefore
  \rowcolor{Gray}{1}
\Body
Version & Date & Author & Reason of Change \\
0.1 & \today & Chen How & dummy content \\
 & & & \\
 & & & \\
\end{NiceTabular}
\end{center}
\caption{Document history}
\end{table}
\end{document}
F. Pantigny
  • 40,250