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

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

### \hhline resets \rowcolors

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.

\documentclass[a4paper,12pt]{article} \usepackage{hhline}\usepackage[table]{xcolor} \begin{document} \begin{table}\rowcolors{1}{white}{gray} %coloured as I expect and want	\begin{tabular}{llll}		1&2&3&4\\ %white		1&2&3&4\\ %grey		1&2&3&4\\ %white		1&2&3&4\\ %grey	\end{tabular}\end{table} \begin{table}\rowcolors{1}{white}{gray} %third row unepextedly grey, final row white	\begin{tabular}{llll}		1&2&3&4\\ %white		1&2&3&4\\ \hhline{----} %grey		1&2&3&4\\ %grey		1&2&3&4\\ %white	\end{tabular}\end{table} \begin{table}\rowcolors{1}{white}{gray} %final row not grey as expected	\begin{tabular}{llll}		1&2&3&4\\ %gwhite		1&2&3&4\\ %grey		1&2&3&4\\ \hhline{----} %white		1&2&3&4\\ %white	\end{tabular}\end{table} \end{document}

Stefan Kottwitz
Site Admin
Posts: 9156
Joined: Mon Mar 10, 2008 9:44 pm
Very interesting! Following those thoughts, doubling the \hhline may look ok again:

\documentclass[a4paper,12pt]{article}\usepackage{hhline}\usepackage[table]{xcolor}\begin{document}\begin{table}\rowcolors{1}{white}{gray}  \begin{tabular}{llll}    1&2&3&4\\ %white    1&2&3&4\\ \hhline{----}\hhline{----} %grey    1&2&3&4\\ %white    1&2&3&4\\ %grey  \end{tabular}\end{table}\end{document}

Stefan
Site admin

Linguist
Posts: 39
Joined: Mon Nov 07, 2011 12:07 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.

Stefan Kottwitz
Site Admin
Posts: 9156
Joined: Mon Mar 10, 2008 9:44 pm
Then try adding \hhline{~} instead:

\documentclass[a4paper,12pt]{article}\usepackage{hhline}\usepackage[table]{xcolor}\begin{document}\begin{table}%\rowcolors{1}{white}{gray}  \begin{tabular}{llll}    1&2&3&4\\ %white    1&2&3&4\\ \hhline{----}\hhline{~} %grey    1&2&3&4\\ %white    1&2&3&4\\ %grey  \end{tabular}\end{table}\end{document}

Stefan
Site admin

Linguist
Posts: 39
Joined: Mon Nov 07, 2011 12:07 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 3 guests