# Making spacing after rule at top of page in booktabs longtable consisting with that after other rules in the same table

Appropriately placed, the longtable package code \midrule\endhead places a horizontal rule before the first row on each page after the first produced by a longtable environment. The below simple code produces a table that bleeds onto the second page, but the first rule on the second page---produced by the above commands---is too high above the text in the first row on that page, creating an unevenly sized row.

(Red box added after screenshot for emphasis.)

How can I make this row have the same size as the other (one-line) rows in the table?

\documentclass[11pt, a4size]{article}
\usepackage{booktabs}
\usepackage{longtable}

\begin{document}

\begin{longtable}[t]{p{15cm}}
\textbf{Lorem ipsum}
\endfirsthead

\midrule
\endhead

\bottomrule
\endlastfoot

\toprule
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \\
\midrule
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \\
[...a few dozen repetitions...]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \\
\midrule
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \\
\midrule
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. \\
\midrule
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \\
\midrule
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \\
\end{longtable}

\end{document}

## 1 Answer

Edit It seems that you find a misfeatures/bug of a longtable using \midrule after column headers on the next pages. This should not happen (see description on the top of page 7 in the package manual).

As possible solution for your problem is use of the \specialrule (see MWE below, which consider that people usually repeat columns' headers on each pages):

\documentclass[11pt, a4size]{article}
\usepackage{booktabs,longtable}

\usepackage{lipsum}
\begin{document}

\begin{longtable}[t]{p{15cm}}
\caption{Lorem ipsum}
\label{tab:mylongtabletest} \\
\toprule
\textbf{Column header}      \\
\midrule
\endfirsthead
\toprule
\textbf{Column header}      \\
% Adding \midrule here introduce undesired vertical space
% between column header and text below on the next page(s).
% As solution can be used `specialrule as follows:
\specialrule{\lightrulewidth}{\abovetopsep}{0pt} % <--------
\endhead
\multicolumn{1}{r}{\footnotesize\emph{Continue on the next page}}   \\
\endfoot
\bottomrule
\endlastfoot
% table body
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
\lipsum[66] \\
\midrule
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \\
\end{longtable}

\end{document}

Now the vertical spacing is as expected.

(first page)

(second page)

• Thanks, Zarko. I'll consider using repeated headers. As for using \hline, it works, with a proviso. The resulting spacing appears correct, but by default a \midrule has thickness 0.4pt but /hline a thickness of 0.05em. To achieve a consistent thickness one needs to call \setlength{\arrayrulewidth}{0.05em} before the first appearance of /hline in the table. – Travis Sep 17 '19 at 17:14
• @Travis, I didn't bother with thickness of horizontal lines in hope, that you will like the first example wit repeated column headers where vertical spaces are consistent with use of \midrule (or \toprule) for the top line in of tables' parts on the next pages:-) – Zarko Sep 17 '19 at 18:21
• I've experimenting with keeping the header, but the above code doesn't actually appear to resolve the issue. The second image doesn't seem to be from a compilation of the first code block, as the content is too short (I assume this was done for brevity), but that code doesn't include a \midrule in \endhead, so the headers on the second and later pages do not have a rule underneath them. When you insert a \midrule there (and extend the table content so that it spills onto a second page), the problem still persists: i.imgur.com/5GNTxgb.png – Travis Sep 17 '19 at 18:29
• I wonder whether this is actually the intended behavior of booktabs, so that the space between the rule under the header and the text in the top row of regular content is the same as the space between the text in two consecutive rows. If so, booktabs evidently was not designed with tables like this (with rules between every entry) in mind. – Travis Sep 17 '19 at 18:31
• @Travis, you are right. Apparently you find a misfeatures/bug in longtable. I corrected my answer accordingly. – Zarko Sep 18 '19 at 3:34