1

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:

There are unwanted gap above footer and bug under it

How to fix this?

  • why do you need to do this, longtable is calculating teh number of lines that fit already? But the extra cell at the bottom of the foot is because you started a new cell after the \hline with \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:31
  • I am designing class journal and after filling goup list I need to fill rest of table with blank rows. The whole idea is gotten from there: link but I do not understand some magic (espetialy magic numbers).

    If I put \mysetpos{\string\zposlast}% before \hline I get error ERROR: Misplaced \noalign. If I put \mysetpos{\string\zposlast}% before // I can not calculate the hight of row... So how to be?

    – Dimitry N. Sep 04 '17 at 14:46
  • By the way, is it possible to ask longtable to drop blank rows, wich go on the nex page? – Dimitry N. Sep 04 '17 at 14:52
  • And what is nature of gap (extra space) between 47 row and foot row ? – Dimitry N. Sep 04 '17 at 15:13
  • you could use \noalign{\mysetpos{\string\zposlast}} – David Carlisle Sep 04 '17 at 15:13
  • It is not a gap it is a row with just one cell, as for the one after the foot you are starting a new cell to do all your loop calculations) – David Carlisle Sep 04 '17 at 15:15
  • what placed in this addition sel/row? and why this not placed in foot row? PS: placing \noalign{\mysetpos{\string\zposlast}} betwin \\ and \hline provide wrong calculation of the row's high – Dimitry N. Sep 04 '17 at 15:33

1 Answers1

1

Now I have a solution wich work for me

  • I have had to rearenge code --- now I calculate height of first added row not the foot row's height
  • The false test wich finish loop generate (start) a сell "without" row, wich look like garbage at the output. so I need to add code, generating full row starting from the cell.

So my table will always have at least 3 extra blank row...

\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%
%  \rule{.5 cm}{.4pt}%
  \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((\zposmiddle-\zposlast)/(\zposfirst-\zposmiddle))}
 \fi

\begin{longtable}{|l|l|l|c|}
  \hline
  THe&head&line&ypos 
  \tabularnewline \hline \endhead
  \mysetpos{\string\zposlast}%
  The&foot&line& \\ \hline%
  \endfoot
a &b&c&d \\ \hline
&&&\\ \hline
&&&\\ \hline
&&&\\ \hline
&&&\\ \hline
  \mysetpos{\string\zposfirst}%
  \whiledo{\value{LoopCNT} < \MYcount}{%
    \addtocounter{LoopCNT}{1}\theLoopCNT\myline%
    \mysetpos{\string\zposmiddle}%
  }
  \myline
\end{longtable}
\end{document}

enter image description here

But there still esthetic question: how add indention to the output in .out file?