LaTeX forum ⇒ Graphics, Figures & Tables\hhline resets \rowcolors Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
Linguist
Posts: 38
Joined: Mon Nov 07, 2011 12:07 pm

\hhline resets \rowcolors

Postby Linguist » Fri Jun 22, 2018 6:24 pm

Hello,

I've encountered a weird problem whereby use of \hhline causes \rowcolors to mess up. It is like the \hhline is itself treated as a row (which is then 'coloured')

So, if I have \rowcolors{1}{white}{gray} before a tabular, every second row should be grey. And this is indeed what happens without any \hhlines (first table in MWE). However, if I have an \hhline after the second row the following row is unexpectedly grey (2nd table in MWE) and if I have an \hhline after the third row the following row is unexpectedly white.

I've tested barious permutations of this with different combinations of \hhline and numbers of rows, and the best understanding of the problem I can come up with is that \hhline is somehow treated like its own row which is then "coloured". (But you see no effect because \hhline isn't actually a row, I think...) So if you use \hhline for every row, none will be coloured.

Not sure if there's anything obvious I'm missing.

  1. \documentclass[a4paper,12pt]{article}
  2.  
  3. \usepackage{hhline}
  4. \usepackage[table]{xcolor}
  5.  
  6. \begin{document}
  7.  
  8. \begin{table}\rowcolors{1}{white}{gray} %coloured as I expect and want
  9. \begin{tabular}{llll}
  10. 1&2&3&4\\ %white
  11. 1&2&3&4\\ %grey
  12. 1&2&3&4\\ %white
  13. 1&2&3&4\\ %grey
  14. \end{tabular}
  15. \end{table}
  16.  
  17. \begin{table}\rowcolors{1}{white}{gray} %third row unepextedly grey, final row white
  18. \begin{tabular}{llll}
  19. 1&2&3&4\\ %white
  20. 1&2&3&4\\ \hhline{----} %grey
  21. 1&2&3&4\\ %grey
  22. 1&2&3&4\\ %white
  23. \end{tabular}
  24. \end{table}
  25.  
  26. \begin{table}\rowcolors{1}{white}{gray} %final row not grey as expected
  27. \begin{tabular}{llll}
  28. 1&2&3&4\\ %gwhite
  29. 1&2&3&4\\ %grey
  30. 1&2&3&4\\ \hhline{----} %white
  31. 1&2&3&4\\ %white
  32. \end{tabular}
  33. \end{table}
  34.  
  35. \end{document}

User avatar
Stefan Kottwitz
Site Admin
Posts: 8945
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Fri Jun 22, 2018 10:40 pm

Very interesting! Following those thoughts, doubling the \hhline may look ok again:

  1. \documentclass[a4paper,12pt]{article}
  2. \usepackage{hhline}
  3. \usepackage[table]{xcolor}
  4. \begin{document}
  5. \begin{table}\rowcolors{1}{white}{gray}
  6. \begin{tabular}{llll}
  7. 1&2&3&4\\ %white
  8. 1&2&3&4\\ \hhline{----}\hhline{----} %grey
  9. 1&2&3&4\\ %white
  10. 1&2&3&4\\ %grey
  11. \end{tabular}
  12. \end{table}
  13. \end{document}


Stefan
Site admin

Linguist
Posts: 38
Joined: Mon Nov 07, 2011 12:07 pm

Postby Linguist » Sat Jun 23, 2018 6:15 pm

I’ve tried this, and indeed doubling \hhline does fix the row colouring issue, but it doubles the thickness of the line.

So we’re halfway there.

I should also note that exactly the same problem arises with \cline (though there are separate issues with \cline not rendering nicely with coloured table rows in many PDF readers). But this issue doesn’t arise with \hline.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8945
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sat Jun 23, 2018 11:43 pm

Then try adding \hhline{~} instead:

  1. \documentclass[a4paper,12pt]{article}
  2. \usepackage{hhline}
  3. \usepackage[table]{xcolor}
  4. \begin{document}
  5. \begin{table}%\rowcolors{1}{white}{gray}
  6. \begin{tabular}{llll}
  7. 1&2&3&4\\ %white
  8. 1&2&3&4\\ \hhline{----}\hhline{~} %grey
  9. 1&2&3&4\\ %white
  10. 1&2&3&4\\ %grey
  11. \end{tabular}
  12. \end{table}
  13. \end{document}


Stefan
Site admin

Linguist
Posts: 38
Joined: Mon Nov 07, 2011 12:07 pm

Postby Linguist » Sun Jun 24, 2018 2:41 pm

Perfect!

And as far as I can see, this doesn’t introduce any unwanted space/gaps either.


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 6 guests