# ltablex and booktabs

I need a table which is larger than one page and it should have a fixed size. To improve the look, I use booktabs. However, the foot of the table is not nice on all pages, except on the last page. Here is my MWE

\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{blindtext}
\begin{document}
\begin{tabularx}{\linewidth}{XX}
left & right\\\toprule
\bottomrule
\endfoot
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\
\end{tabularx}
\end{document}


Is there a possibility to detect, if a row will be the last row on a page? Than I would be able to avoid the double line. Like the following pseudo code

is row last row of the page than \bottomrule else \midrule


I would like to have only a \bottomrule at the end of each page but no double line

• Not an answer to your question, but possibly of some relevance anyway: For your MWE at least (and possibly your real document too), you may want to replace \toprule with \midrule[\heavyrulewidth] since the rule at the top of each page actually has some material above it (as well as below it, of course). – Mico Mar 25 '14 at 16:11
• A pagebreak is only possible after a tabular line and not within a tabular line! So you always have a \midrule because you use \\\midrule after each tabular row. Replace \endfoot with \endlastfoot and use only a \\ for the last tabular row. – user2478 Mar 31 '14 at 18:44
• the problem is, I can not use \\ for the last tabular row on each page, because I do not know, how many rows are there (the tables are generated) – Micha Mar 31 '14 at 18:58
• I realise this is probably a really dumb question but what does \\*  do that's different from \\ ? (It isn't possible to format just two backslashes as code here?) – cfr Apr 3 '14 at 23:40

Solution A) I am not sure if I am following the question, but you don't need \bottomrule at all, it is a simple rule where you can only set a width of it. In my example I am removing it and I am adding one extra rule at the very end of the table.

%! *latex mal-ltablex-a.tex
\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{blindtext}

\begin{document}
\begin{tabularx}{\linewidth}{XX}
left & right\\\toprule
%\bottomrule
\endfoot
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\*\midrule
\end{tabularx}
\end{document}


Edit, Solution B) In case you really need that, I am using this trick as a patch. I am saving information about page number (\label) at the end of each row and in next runs of TeX I am deciding if to typeset \midrule or \bottomrule (I am comparing actual and the following row -- it is a looking ahead situation).

In case you would like to have \bottomrule at the very end of your table, please comment out \mycounting written on the before the last line.

%! *latex mal-ltablex-b.tex
\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{blindtext}
\usepackage{refcount}

\let\oldmidrule=\midrule
\newcount\malic
\global\malic=0
\newcount\maltempa \maltempa=0
\newcount\maltempb \maltempb=0

\def\midrule{%
\mycounting
\ifnum\maltempa=\maltempb
\\*\oldmidrule
\else
\\*\bottomrule[6pt]
\fi
}%End of \midrule...

\def\mycounting{%
\maltempb=\getpagerefnumber{mycounter-\the\malic}%
\maltempa=\getpagerefnumber{mycounter-\the\malic}%
\typeout{\the\maltempa, \the\maltempb}
\label{mycounter-\the\malic}%
}% End of \mycounting...

\begin{document}
\begin{tabularx}{\linewidth}{XX}
left & right\\\toprule
%\bottomrule
\endfoot
\blindtext & \blindtext \midrule
\blindtext & \blindtext \midrule
\blindtext & \blindtext \midrule
\blindtext & \blindtext \midrule
\blindtext & \blindtext \midrule
\blindtext & \blindtext \midrule
\blindtext & \blindtext \midrule
%\blindtext & \blindtext \midrule
\end{tabularx}

\mycounting % Comment out this line in case you would like to have \bottomrule at the very end of the table...
\end{document}


In your example, there seems to be little point -- typographically speaking -- of having both "heavy" rules (generated by \toprule and \bottomrule) and "light" rules (generated by \midrule). I therefore suggest you use only one rule width, say, \heavyrulewidth, for all rules. Here's how you might implement such a setup:

\documentclass{scrartcl}
\usepackage{booktabs,ltablex,blindtext}
\setlength\lightrulewidth{\heavyrulewidth}
\begin{document}
\begin{tabularx}{\linewidth}{XX}
left & right\\ \toprule
\bottomrule % use \bottomrule only on final page
\endlastfoot
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\
\end{tabularx}
\end{document}


Conversely, if you prefer to have all rules have the thickness of \lightrulewidth, you'd issue the instruction

\setlength\heavyrulewidth{\lightrulewidth}


This addresses the issue by moving up vertically a faux \bottomrule (the \raisebox contents) to overlay any residual \midrule, thus avoiding the appearance of a double rule. There is, however, a side effect: an extra line of vertical space is taken by this manipulation, and so one has one less row to work with per page. To see this, comment out my \raisebox and uncomment the original \bottomrule and you will find the "X Y" row move from the top of page 2 to the bottom of page 1.

\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{blindtext}
\begin{document}
\begin{tabularx}{\linewidth}{XX}
left & right\\\toprule
\raisebox{9pt}{\smash{\makebox[.972\textwidth]{\rule{\textwidth}{1pt}}}}%
%\bottomrule
\endfoot
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\*\midrule
X & Y\\*\midrule
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\*\midrule
\blindtext & \blindtext\\
\end{tabularx}
\end{document}


Does this code (I replaced \endfoot with \endlastfoot) give what you want?

    \documentclass{scrartcl}%
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{blindtext}
\begin{document}
\begin{tabularx}{\linewidth}{XX}
left & right\\\toprule
\bottomrule
\endlastfoot
\blindtext & \blindtext\\\midrule
\blindtext & \blindtext\\\midrule
\blindtext & \blindtext\\
\end{tabularx}
\end{document}


• no, I'm interested to have one bottomrule at the end of each page but no double line (midrule and bottomrule) – Micha Mar 25 '14 at 8:00
• @Micha: I modified my answer. Is that OK now? – Bernard Mar 25 '14 at 8:14
• @Micha: Pardon me, but what is the difference between you second image and what I've produced? I surely do miss something. – Bernard Mar 25 '14 at 15:10
• @Micha; Oh! I see. I thought what bothered you was the double line at the end of first page. So, just to be sure, you want a \bottomline at the end of each intermediate page ? – Bernard Mar 25 '14 at 15:35
• Yes, I would like to have only a \bottomrule at the end of each page but no double line – Micha Mar 25 '14 at 15:44

Not a real solution:

\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{ltablex,tabu}
\usepackage{blindtext}
\begin{document}
\begin{tabularx}{\linewidth}{XX}
left & right\\\midrule[\heavyrulewidth]
\multicolumn{2}{@{}c@{}}{continues next page} \\*\bottomrule
\endfoot
\bottomrule
\endlastfoot
\blindtext & \blindtext\\\midrule
\blindtext & \blindtext\\\midrule
\blindtext & \blindtext\\
\end{tabularx}
\end{document}


In this problem, you ask two problems

Problem 1: How to make an long table with every page ends with \bottomrule.

It is easier to solve, just delete the second \middlerule.

\begin{tabularx}{\linewidth}{XX}
left & right\\ \toprule
\bottomrule
\endfoot
\blindtext & \blindtext\\ \midrule
\blindtext & \blindtext\\
\blindtext & \blindtext\\
\end{tabularx}


And results are shown below:

Problem 2: You want the code having the ability to determine whether the page is end with that ''row''.

As I known, the end of table and end of row are implemented in different ways. The headline and footline are defined at the begin of the table,

left & right\\ \toprule

\blindtext & \blindtext\\ \midrule

I have no ability to determine the appearance of \middlerule or not, unless they are defined in same way. Generally we use ''spacing'' instead of lines.