I Updated the MWE to address comments by David. Now I am using a CSV-file ('unknown number of records'). This give the same 'header-only/bottom line' (tested in Overleaf) on page last page. How to get this always working nicely (independent of number of records)?
I have a problem with longtable. A longtable sometimes produces an "empty" last table page (that is only a header and a bottom line, so no data lines).
(credits) I changed the MWE of this tex.stackexchange.com post to demonstrate the problem.
More in general: how can I get the longtable behaviour: "if the remaining number of records is less than x skip them to the next page even if the current page is not full". So then I can say do the last [2,3,4 or 5] (and total count is higher else we are in an endless loop) on a new page to avoid I get a ugly 1 item table on the last page.
MWE Last page screenshot (Overleaf generated):
MWE Code
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{demo.csv}
col
a
b
c
d
e
f
g
h
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
z1
\end{filecontents}
\usepackage{array}
\usepackage{setspace}
\usepackage{datatool}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage[english]{babel}
\usepackage[pangram]{blindtext}
\usepackage{lscape}
\begin{document}
\setstretch{1.03}
\blindtext[5]
\begin{landscape}
\DTLloaddb{dset}{demo.csv}
\begin{longtable}{>{\raggedright}p{7cm}>{\centering}p{7cm}}
\toprule
Header & \\
\midrule
\endhead
\bottomrule
\endfoot
\endlastfoot
\DTLforeach*{dset}{\COL=col}%
{\COL & t\tabularnewline}%
\end{longtable}\end{landscape}
\end{document}

\endlastheadbut the new question is not really about longtable at all it's about datatool and whether it can do that (which I don't know, offhand. – David Carlisle Oct 17 '16 at 09:31sfamily) and change that, I updated it to reflect my real issue. – robert Oct 17 '16 at 09:35