1

I have created a dark mode TeXworks setup that I really like (and will post as an answer to How can I set a dark theme in TeXworks? when this issue is resolved) but the white preview page is too bright. I have managed to get figure captions to appear in white, text colour to appear in white and the page colour to be black but I am at a loss as to how to change a table (header, lines, data) from all black to all white. I could not see any questions on this but I am happy to be corrected if this is a duplicate. The closest I could find was on How to change the colour of the all lines in tabularx? but this does not change the data or headers.

This is my current dark mode TeXworks setup so you can see the motivation for wanting rough drafts of documents to have black paper/white ink:

enter image description here

On my big monitor, that is too bright for hours of working on documents so I would prefer for it to resemble this (I typically have 3 windows open on the same screen, a main file with arara commands, a .tex file I am working on in the middle that is \included by main and the preview on the right):

enter image description here

What I currently have is this (the table code I copied just for this question from an answer by Mico):

enter image description here

In white it looks like this:

enter image description here

I have stripped most of my formatting code so I know the text doesn't look the best, it is just for the MWE:

\documentclass{article}

\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[font={color=white}]{caption} % comment out to revert to normal
\usepackage{tabularx}

\begin{document}

\pagecolor{black} % comment out to revert to normal
\color{white}     % comment out to revert to normal

\lipsum[1-2]

\begin{table}
\caption{This text is correctly formatted in white but the table is still in all black.}
\begin{tabularx}{\textwidth}{@{}ccccc@{}}
\hline
movieId & damp\_avg\_rating & count\_r & sum\_r & average\_r \\ 
\hline
     318 & 3.1538461538461537 &     251 & 1107.0 &  4.410358565737051 \\
     356 &  3.008403361344538 &     257 & 1074.0 &  4.178988326848249 \\
    2571 & 2.9454545454545453 &     230 &  972.0 &  4.226086956521739 \\
\hline
\end{tabularx}
\end{table}
    
\begin{figure}
\caption{This text is correctly formatted in white.}
\end{figure}

\end{document}

I am not sure how to go about handling this as it appears to be out of my understanding, most table questions on here concern shading or changing \hline colours, not the entire table. I only want this in documents whilst they are rough and in the preview window, the final documents will be in the usual standard white paper and black text.

I do not particularly want to have to edit each tables code, it would be nice if the source could be unchanged in my \include files, a global command or code in the preamble or just after \begin{document} that affects all \begin{table} environments or whatever would be best would be ideal if possible please.

1 Answer 1

0

Was easier then I expected although I have little experience with the etoolbox so apologies for the question. Using:

\pagecolor{black}\color{white}

to change the the page and main text colour to black and white respectively with:

\AtBeginEnvironment{tabularx}{\color{white}\arrayrulecolor{white}}

to change the tabularx environment worked and the dark mode is fully implemented. It would probably be best to put these commands in a .sty file that can be imported when further issues arise with listings and other table environments but it works.

enter image description here

Code:

\documentclass{article}

\usepackage{lipsum}
\usepackage[table]{xcolor}
\usepackage[font={color=white}]{caption}
\usepackage{tabularx}
\usepackage{etoolbox}

\pagecolor{black}\color{white}
\AtBeginEnvironment{tabularx}{\color{white}\arrayrulecolor{white}}


\begin{document}

\lipsum[1-2]

\begin{table}
\caption{This text is correctly formatted in white but the table is still in all black.}
\begin{tabularx}{\textwidth}{@{}ccccc@{}}
\hline
movieId & damp\_avg\_rating & count\_r & sum\_r & average\_r \\ 
\hline
     318 & 3.1538461538461537 &     251 & 1107.0 &  4.410358565737051 \\
     356 &  3.008403361344538 &     257 & 1074.0 &  4.178988326848249 \\
    2571 & 2.9454545454545453 &     230 &  972.0 &  4.226086956521739 \\
\hline
\end{tabularx}
\end{table}

\begin{figure}
\caption{This text is correctly formatted in white.}
\end{figure}

\end{document}
1
  • 1
    You may ask for reason of such behavior. Colorization is done by color-stack method. This method needs to set black many objects in output routine. Your example shows that output routine sets explicitly to black the TeX inserts (i.e. floating object, table in your example) and the footer (pagination). If it is undone then you have pagination (for example) red when you set a single paragraph at the end of page red. Another colorization principle (more natural for users) is based on LuaTeX attributes. In LaTeX you must to use package luacolor, in OpTeX color attributes are default.
    – wipet
    Oct 2, 2022 at 4:18

You must log in to answer this question.

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