8

Are there known issues with the appearance of white text on black background?

When I use several \hline in a table I get different appearances for the lines. It could appear as normal or weak or entirely missing. Only when I magnify to about 400% do I see the lines consistently.

Assuming this is a hardware issue I tried on a different monitor and same thing showed up. I tried the booktabs package to get custom thickness for the lines but that package puts a band of space around its \hrule causing disconnected appearance if you have a vertical rule. (booktabs discourages vertical rules in a table.)

(Final Edit: I eventually agreed with booktabs, gave up on vertical rule, and got consistent looking white rules on black ground for a table.)

Sample code would be as in white text on black background in entire table:

\documentclass[11pt,letterpaper]{article}
\usepackage[table]{xcolor}
\usepackage{array}
\begin{document}
\begin{table}[H]
  \caption{Caption}
  \label{Table1}
  \begin{center}
    \arrayrulecolor{white}
    \newcolumntype{B}{>{\columncolor{black}\color{white}}c}
    \begin{tabular}{  B  l   | B  p{6in}   }
      \hline\hline
      Text 1 & Text 2 \\
      \hline\hline
      Text 3 & Text 4 \\
      \hline
    \end{tabular}
  \end{center}
\end{table}
\end{document}
David Carlisle
  • 757,742
Maesumi
  • 9,059
  • How do they look when printed? – qubyte Apr 17 '12 at 10:12
  • 3
    That usually a zooming issue of the PDF viewer. Adobe Acrobat Reader for example shows certain line with variable thickness at different zoom levels. E.g. the vertical lines of a rectangle can be sometimes thicker or thinner than the horizontal ones. Sometimes thinner lines are not shown at all with certain zoom levels. Also, background color is usually a sort of fill, which can be overlapping with rules in the neighborhood. This has to do AFAIK with the drawing and zooming rules followed by the PDF viewer. We already had a couple of similar questions like this here. – Martin Scharrer Apr 17 '12 at 10:12
  • 3
    General note: The common format for package names here is \packagename`` and they should be linked to its webpage on CTAN, not to a PDF on a specific mirror, i.e. http://www.ctan.org/pkg/packagename. No biggy. – Martin Scharrer Apr 17 '12 at 10:18
  • 1
    In addition to what @MartinScharrer said, try to turn off all kinds of "smoothing" features in the reader settings. Those visual optimizations can make small things disappear. – Stephan Lehmke Apr 17 '12 at 10:27
  • By default, the value of \arrayrulewidth is 0.4 pt, you can try to use 0.5 pt or 0.6 pt \setlength{\arrayrulewidth}{0.6pt}. I agree with Martin, often the problem comes from the PDF viewers. Several years ago, we had some strange results on OS X. – Alain Matthes Apr 17 '12 at 10:27
  • 3
  • @MarkS.Everitt: The linked question indeed seems similar, but the solutions don't work here (the OP is already using xcolor, and adding the xcdraw option doesn't seem to make a difference). – Jake Apr 17 '12 at 11:46
  • @Jake: I was pointing to it mainly because this is a viewer problem rather than a LaTeX problem, which the questions have in common. Admittedly not quite an exact duplicate in hindsight, but I think that it's close enough. – qubyte Apr 17 '12 at 11:54
  • @everitt The document is only appropriate for viewing on a terminal, given that the page is all black. But if it helps with diagnostics let me know and I will print a page. – Maesumi Apr 17 '12 at 13:35
  • You need to @ my first name, and the comment box will auto-complete it for you. @everitt does not go to my inbox I'm afraid! – qubyte Apr 17 '12 at 15:56
  • @StephanLehmke Thanks, but the document is for external use, so the solution cannot be dependent on fine-tuning the PDF reader. – Maesumi Apr 17 '12 at 17:16

2 Answers2

5

I guess this comes from the fact that the black filling and the white lines are treated differently by the PDF reader, which assumes that the black filling is more important than the white lines, presumably treating the black filling similarly to how text would be treated usually.

When using TikZ to draw the table (based on TikZ matrix as a replacement for tabular), this problem doesn't appear. That approach takes more work (you'll have to set the column widths by hand), so it might well not be feasible for your needs, but if it's just for a simple table that needs to display well on screen at all zoom levels, it might do:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\begin{document}
\begin{tikzpicture}[
    table/.style={
        minimum height=1.5em,
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        text depth=0.5ex,
        text height=2ex,
        nodes in empty cells
    }
]


\matrix [
    table,nodes={
        text width=0.5em,
        draw=white,
        text=white,
        fill=black
    },
    column 2/.style={nodes={text width=2em}},
    column 3/.style={nodes={text width=6em}},
    row 1/.style={nodes={text depth=2\baselineskip+0.5ex}},
    row 2/.style={nodes={text depth=\baselineskip+0.5ex}}
]
{
0   &ABC  & This is a long line that will wrap around \\
1   &DEF  & |[align=right]| Woo, right aligned! \\
2   &GHI  & 9 \\
};
\end{tikzpicture}
\end{document}
David Carlisle
  • 757,742
Jake
  • 232,450
  • Thanks. Can you include a paragraph column, as in p{2in}, in the table? – Maesumi Apr 17 '12 at 13:24
  • @Maesumi: You can, but you'll have to set the text depth for that row manually. Again, this might well be more work than you're willing to do. – Jake Apr 17 '12 at 13:57
  • 1
    How do I choose NOT to draw certain lines? For example suppose I do not want the left line or the right line (which bound the table). And, how do I draw a double line, for example under the first row? – Maesumi Apr 25 '12 at 22:19
1

The package nicematrix has tools designed to avoid that problem of some PDF readers. With nicematrix, the rules won't seem to vanish, whatever PDF you use, whatever the zoom level you use.

However, you need several compilations (because nicematrix uses PGF/TikZ nodes under the hood).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{center} \color{white} \begin{NiceTabular}{cp{2em}p{6em}}[hvlines-except-borders,cell-space-limits=2pt] \CodeBefore \arraycolor{black} \Body 0 &ABC & This is a long line that will wrap around \ 1 &DEF & \Block[r]{}{Woo, right aligned!} \ 2 &GHI & 9 \ \end{NiceTabular} \end{center}

\end{document}

Output of the first code

In fact, in this case, it's possible to construct the tabular without white lines that is to say with only black cells (if there is a colored background, that background will be seen between the cells of the tabular).

The following example uses \pagecolor{gray}.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\pagecolor{gray}

\begin{center} \color{white} \begin{NiceTabular}{cp{2em}p{6em}}[cell-space-limits=2pt] \CodeBefore \TikzEveryCell{offset=0.35pt,fill=black} \Body 0 &ABC & This is a long line that will wrap around \ 1 &DEF & \Block[r]{}{Woo, right aligned!} \ 2 &GHI & 9 \ \end{NiceTabular} \end{center}

\end{document}

Output of the second code

F. Pantigny
  • 40,250