6

When I try to color a column red, it seems that white lines begin to emerge. Additionally the \hline changes width depending on how you zoom into the document in pdf format. It look as if the color infringes on the \hline?

Here is a MWE:

\documentclass[11pt,english]{article}
\usepackage{longtable,lscape}
\usepackage{color, colortbl}
\usepackage{bigstrut}
\begin{document}

\begin{table}
\resizebox{\textwidth}{!}{
\begin{tabular}{c>{\columncolor{red}}c}
a                  & b          \bigstrut[b]\\
\hline
1 & 2 \\
3 & 4 \bigstrut[t]\\
\hline 
5 & 6\\
\end{tabular}
}
\end{table}
\end{document}

Any ideas as to what is going on here?

  • The reason behind this is described well in Box border lines not showing properly on PDF, even though it doesn't deal with colortbl explicitly. – Werner Oct 15 '13 at 19:25
  • when i try to load xcolor, i get an option clash with another package, how do i deal with this to attempt to use the solution in that answer? – Alex Oct 15 '13 at 19:40
  • 1
    use \usepackage[table]{xcolor} and if you get an option clash then use befor \documentclass the command \PassOptionsToPackage{table}{xcolor} and then load xcolor without an optional argument. – user2478 Oct 15 '13 at 19:42
  • @Alex: What I meant with "described well" is that the problem is very similar to that of the linked post. Readers render the content in order to display it. These rendering algorithms are restricted by the display resolution or perhaps the algorithm. Most notably the output is constrained by the pixels on your screen. So, in some instances, perhaps a combination of the above-mentioned restrictions, you might not see a line (either vertical or horizontal) or it is of different width than others. – Werner Oct 15 '13 at 19:46
8

Your example works if the xcolor instead of the color package is loaded while specifying the table option (which loads the colortbl package in a suitable way).

enter image description here

Regarding your second point, viz., about the color block impinging on the black line: This impression may be an artifact of limited screen resolution; it's definitely apparent in the .png image posted here, but that's a raster font image with limited resolution. The uneven line thickness thing appears to go away if you (a) increase the resolution or (b) make a paper hardcopy.

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{bigstrut}
\begin{document}
\begin{table}
\centering
\begin{tabular}{c>{\columncolor{red}}cr}
a                  & b       & c   \bigstrut[b]\\
\hline
1 & 2 & 3\\
4 & 5 & 6 \bigstrut[t]\\
\hline 
7 & 8 & 9\\
\end{tabular}
\end{table}
\end{document}
  • in the graphic you posted, do you see how the lines are not of the same width? (in the colored column) – Alex Oct 15 '13 at 19:43
  • @Alex - I've posted a follow-up comment on this topic. The image file I've posted is a low-resolution .png (raster font) pic. The issue with the uneven line thickness appears to go away if you (a) increase the resolution (and magnification) or (b) make a paper hardcopy. – Mico Oct 15 '13 at 19:47
  • thank you very much for looking into this. the problem is i need this for a presentation so the way it displays in pdf format is critical. – Alex Oct 15 '13 at 19:50
  • In an ideal world in which colour support was not added a decade after the system was designed, there would be a single red panel with the horizontal rules crossing it, this would be far less susceptible to pixel alignment artefacts in the rendering. But what colortbl actually does is place the coloured panels adjacent to the vertical rules, one in each cell, this means that unless the renderer is very careful rounding artefacts can make the boundaries snap up or down a pixel and make the rule widths change and/or white gaps appear. – David Carlisle Oct 15 '13 at 20:09
  • @Alex - As mentioned in the posting tex.stackexchange.com/a/11771/5001 as well as by David Carlisle in this comment, the issue of the color blocks impinging on the black lines is entirely an artifact caused by rounding errors in the pdf previewers. I don't know what more to say about this. – Mico Oct 15 '13 at 20:12
6

You can help the renderer by placing the rules over a single red panel, but to do that you have to give TeX a bit more help.

enter image description here

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{bigstrut}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ccr}
\omit&\omit
{\color{red}%
\leaders\hbox{\smash{\vrule height 2pt depth 55pt}}\hskip 0pt plus 1filll%
}%
&
\omit\cr
a                  & b& c   \bigstrut[b]\\
\hline
1 & 222jjj2 & 3\\
4 & 5 & 6 \bigstrut[t]\\
\hline 
7 & 8 & 9\\
\end{tabular}
\end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.