8

I have a zebra-striped longtable such as the following:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{lipsum}

\begin{document}

\lipsum[9-13]

\rowcolors{2}{white}{gray!25}
\begin{longtable}{|m{2cm} m{1.5cm} m{1.5cm} m{1.5cm}|}
\hline
& Value 1 & Value 2 & Value 3 \\ \endhead \hline \endfoot
Item & 0 & 0 & 0 \\
Item & 0 & 0 & 0 \\
Item & 1 & 0 & 0 \\
Item & 2 & 0 & 0 \\
Item & 3 & 0 & 0 \\
Item & 4 & 0 & 0 \\
\end{longtable}

\end{document}

How do I make the coloring restart automatically when the table wraps to a new page so I avoid cases like this where both the header and first row of the new page are white?

The first two rows are both white

3
  • Welcome to TeX.SX!
    – dexteritas
    Jun 12, 2018 at 18:37
  • 3
    not easily sorry, as always in tex page breaking is asynchonous with typesetting page content so the rows are coloured before tex knows what page they are on. easiest would be if you adjust the height of the table head so that an even number of rows fit on the page, so they all start with the same colour. Jun 12, 2018 at 18:40
  • If you don't mind manual intervention you could just add 1 to xcolor's internal table row colour switch at the point where the page break happened. Sep 13, 2018 at 9:31

1 Answer 1

1

Can you accept just a thick rule to avoid having to white rows?

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{longtable}
\usepackage{lipsum, booktabs, colortbl, array}

\begin{document}

\lipsum[9-13]

\rowcolors{2}{white}{gray!25}
\begin{longtable}{|m{2cm} m{1.5cm} m{1.5cm} m{1.5cm}|}
\hline
  & Value 1 & Value 2 & Value 3 \\\arrayrulecolor{gray}
  \specialrule{3pt}{0pt}{0pt}
  \endhead \hline \endfoot
  Item & 0 & 0 & 0 \\
  Item & 0 & 0 & 0 \\
Item & 0 & 0 & 0 \\
Item & 1 & 0 & 0 \\
Item & 2 & 0 & 0 \\
Item & 3 & 0 & 0 \\
Item & 4 & 0 & 0 \\
\end{longtable}

\end{document}

I didn't find a way to get the vertical lines along the thick rule, though. zebra-longtable

1
  • I have a lot of tables of varying lengths and only a couple that are long enough to wrap. We tried a separating line before and it just doesn't look as clean on most of the tables, and we want consistent formatting. We found a different way to do it, but thanks for the suggestion though.
    – JayC
    Jun 25, 2018 at 15:11

You must log in to answer this question.

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