I try to calculate amount rows in table at page. Look like it works, but last line in table is wery strange and I do not understand why.
There is code:
\documentclass{article}
\usepackage[left= 1 cm, right=1 cm, top = 2 cm, bottom = 1 cm]{geometry}
\usepackage{longtable}
\usepackage{ifthen}
\begin{document}
\newcounter{LoopCNT}
\newcommand{\myline}{&&& \\ \hline}
\newcommand{\mysetpos}[1]{%
\pdfsavepos%
\write\csname @auxout\endcsname{%
\string\ifx#1\string\undefined}%
\write\csname @auxout\endcsname{%
\string \gdef #1{\the\pdflastypos}}%
\write\csname @auxout\endcsname{%
\string\fi%
}}%
\ifx\zposlast\undefined
\newcommand{\MYcount}{70}
\else
\edef\MYcount{\the\numexpr((\zposfirst-\zposprev)/(\zposprev-\zposlast))}
\fi
\providecommand{\zposfirst}{}
\providecommand{\zposprev}{}
\providecommand{\zposlast}{}
\zposfirst; \zposprev; \zposlast; \MYcount
\begin{longtable}{|l|l|l|c|}
\hline
THe&head&line&ypos % \endhead
\tabularnewline \hline \endhead
\mysetpos{\string\zposprev}%
The&foot&line& \\ \hline%
\mysetpos{\string\zposlast}%
\endfoot
a &b&c&d \\ \hline
&&&\\ \hline
&&&\\ \hline
&&&\\ \hline
&&&\\ \hline
\mysetpos{\string\zposfirst}%
\whiledo{\value{LoopCNT} < \MYcount}{%
\addtocounter{LoopCNT}{1}\theLoopCNT\myline%
}
\end{longtable}
\end{document}
And I get in result:
How to fix this?


\hlinewith\mysetpos{\string\zposlast}%which produces no text but does make a table cell so you see the empty cell. – David Carlisle Sep 04 '17 at 12:31If I put
– Dimitry N. Sep 04 '17 at 14:46\mysetpos{\string\zposlast}%before\hlineI get error ERROR: Misplaced \noalign. If I put\mysetpos{\string\zposlast}%before//I can not calculate the hight of row... So how to be?\noalign{\mysetpos{\string\zposlast}}– David Carlisle Sep 04 '17 at 15:13\noalign{\mysetpos{\string\zposlast}}betwin\\and\hlineprovide wrong calculation of the row's high – Dimitry N. Sep 04 '17 at 15:33