I have a long table spread over a few pages, made of groups of rows. I use the packages longtable, booktabs, multirow and multicol, and have read their documentation, but could not find answers to my problem. For mwe, see below.
I have two (related) problems with this, all about the page breaks:
- The page break should not happen within a group of rows, as happens now on pages 1 and 2. I have a workaround of putting \nopagebreak behind every line, but I hope that there is a smarter solution.
- I separate my groups or rows with \midrule, but if these groups are already separated by a page break, I don't need \midrule anymore, it makes an ugly extra line, see the top of page 4.
Is there a way to "group" my rows in a way that latex understands, so page breaks do not fall in the middle of a multirow, and that midrules separating these multirows are not used around pagebreaks?
\documentclass[a5paper,12pt]{article}% smaller paper size to show the problem
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\begin{document}
This is a test.
\begin{longtable}{lll}
\caption{Table to show problem}\\
\toprule
Year & Category & Used\\
\midrule
\endfirsthead
\multicolumn{3}{c}%
{\tablename\ \thetable\ -- \textit{Continuation of previous page}} \\
\toprule
Year & Category & Used \\
\midrule
\endhead
\hline \multicolumn{3}{r}{\textit{Table is continued on next page}} \\
\endfoot
\bottomrule
\endlastfoot
1933--1939 & 1 & Yes\\
\midrule
\multirow{2}{*}{1947--1948}
& 1 & Yes\\
& 2 & Some\\
\midrule
\multirow{3}{*}{1949--1961}
& 1 & Yes\\
& 2 & No\\
& 3 & No\\
\midrule
\multirow{4}{*}{1962--1970}
& 1 & Yes\\
& 2 & Some\\
& 3 & Some\\
& 4 & Yes\\
\midrule
\multirow{4}{*}{1971--1974}
& 1 & No\\
& 2 & Some\\
& 3 & No\\
& 4 & Yes\\
\midrule
\multirow{5}{*}{1975--1979}
& HC & No\\
& 1 & No\\
& 2 & Yes\\
& 3 & Some\\
& 4 & Yes\\
\midrule
\multirow{5}{*}{1980--1982}
& HC & Yes\\
& 1 & Yes\\
& 2 & Some\\
& 3 & Yes\\
& 4 & Yes\\
\midrule
\multirow{5}{*}{1983--1984}
& HC & Yes\\
& 1 & No\\
& 2 & Some\\
& 3 & Yes\\
& 4 & Yes\\
\midrule
\multirow{5}{*}{1985--1986}
& HC & Some\\
& 1 & Yes\\
& 2 & Yes\\
& 3 & Yes\\
& 4 & Yes\\
\midrule
\multirow{5}{*}{1987--1989}
& HC & Yes\\
& 1 & Some\\
& 2 & Yes\\
& 3 & Yes\\
& 4 & Yes\\
\midrule
\multirow{5}{*}{1990--2003}
& HC & Yes\\
& 1 & Some\\
& 2 & Yes\\
& 3 & Yes\\
& 4 & Yes\\
\midrule
\multirow{5}{*}{2004--2010}
& HC & Yes\\
& 1 & Some\\
& 2 & Yes\\
& 3 & Yes\\
& 4 & Yes\\
\midrule
\multirow{5}{*}{2011}
& HC & Yes\\
& 1 & Yes\\
& 2 & Some\\
& 3 & Yes\\
& 4 & Yes\\
\midrule
\multirow{5}{*}{2012--2016}
& HC & Yes\\
& 1 & Yes\\
& 2 & Yes\\
& 3 & Yes\\
& 4 & Some\\
\midrule
\multirow{5}{*}{2017--2018}
& HC & Yes\\
& 1 & Yes\\
& 2 & Some\\
& 3 & Some\\
& 4 & Yes\\
\end{longtable}
\end{document}
\\*
to suppress page breaks (on a good day)