10

I am looking for a way have white text on black background in the PDF output of PDFLaTeX applied to a document containing a basic table with dividing lines and some colored links. Using

\usepackage{xcolor}
\pagecolor[rgb]{0.,0.,0.}
\color[rgb]{1,1,1}

I gain the desired effect but only outside of the table. I can put

\color[rgb]{1,1,1}

in every cell, but that is not practical and table lines are still black and hence do not show up.

EDIT: Here is a MWE; the tabular makes room for a paragraph and lcr specification.

\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}
1
  • 3
    have you tried colortbl?
    – user11232
    Commented Apr 14, 2012 at 3:32

2 Answers 2

15

You can do this with the [table] option of xcolor (which uses colortbl):

You can use the array package to define column types whose colour is black. E.g.

\newcolumntype{B}{>{\columncolor{black}\color{white}}c}}

defines a B column which is identical to a c column, but black with white text. You can also define similar column types for the other types of columns (l, p and m, for example). For p column types, you need to add hspace{0pt} at the beginning of the cell to avoid odd spacing issues.

\newcolumntype{L}{>{\columncolor{black}\color{white}}l}}
\newcolumntype{P}[1]{>{\columncolor{black}\hspace{0pt}\color{white}}p{#1}}
\newcolumntype{M}[1]{>{\columncolor{black}\hspace{0pt}\color{white}}m{#1}}

Here's an example using each type.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{array}
\begin{document}
\arrayrulecolor{white}
\newcolumntype{B}{>{\columncolor{black}\color{white}}c}
\newcolumntype{L}{>{\columncolor{black}\color{white}}l}
\newcolumntype{P}[1]{>{\columncolor{black}\hspace{0pt}\color{white}}p{#1}}
\begin{tabular}{|B|L|P{1in}|}
\hline
A & B & C \\
\hline
D & E & F \\
\hline
G & H & I \\
\hline
J & K & L \\
\hline
M & N & O \\
\hline
\end{tabular}
\end{document}

output of code

4
  • @Munn I tried with my table and I got mixed results. Questions is what if begin{tabular} has more specs such as edited example above.
    – Maesumi
    Commented Apr 14, 2012 at 19:10
  • @Maesumi I've added some other column types to the example.
    – Alan Munn
    Commented Apr 14, 2012 at 19:56
  • @Munn (Werner) Thanks. Everything works, except when I use \newcolumntype{P}[1]{>{\columncolor{black}\color{white}}p{#1}} I get an extra line in the table with the corresponding cell pushed into the second line. By the way, regarding the ![\hline and \end{document}][1], are they typos?
    – Maesumi
    Commented Apr 14, 2012 at 22:38
  • @Maesumi I've modified the definition of the P column type to fix the spacing issue. (And yes, there were some typos introduced by a bad paste when I was editing.)
    – Alan Munn
    Commented Apr 14, 2012 at 23:10
1

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\color{white}
\begin{NiceTabular}{clp{1in}}[rules/color=white,hvlines-except-borders]
\CodeBefore
\arraycolor{black}
\Body
A & B & C \\
D & E & F \\
G & H & I \\
J & K & L \\
M & N & O \\
\end{NiceTabular}

\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .