10

I want to create a table exactly occupying the whole printed area with no space left. The table consists of 5 rows per page, as follows.

\documentclass[table]{article}
\usepackage[a4paper,margin=1cm,showframe]{geometry}
\usepackage{longtable,array,xcolor}

\newcounter{counter}
\pagestyle{empty}

\newcolumntype\specifier{|%
*2{>{\centering\stepcounter{counter}\thecounter}m{1cm}
    |>{\centering}m{0.5\dimexpr\linewidth-2cm-8\tabcolsep-5\arrayrulewidth\relax}
    |}
}

\makeatletter

\arrayrulecolor{red}

\def\row[#1]#2{%
& \parbox[c][0.2\dimexpr\textheight-6\arrayrulewidth-\topskip\relax][c]{\linewidth}{\centering #1 \par \vspace{15pt} \textcolor{red}{#2}}
\ifodd\value{counter}
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{&}{\tabularnewline\hline}
}

\let\oldendlongtable\endlongtable
\def\endlongtable{%
\ifodd\value{counter}\omit\tabularnewline\cline{1-2}\fi
\oldendlongtable}


\begin{document}
\begin{longtable}{\specifier}\hline
\row[RAM]{Random Access Memory}
\row[BIOS]{Basic Input Output System}
\row[OMG]{Oh My Ghost}
\row[PS]{Post Script}
\row[BJT]{Bipolar Junction Transistor}
\row[DEK]{Donut E. Knot}
\row[B]{Batman}
\row[MS]{Microsoft}
\row[CPP]{C Plus Plus}
\end{longtable}
\end{document}

enter image description here

Problem and Question

The output has an unwanted white space above the table. It is probably caused by my wrong expression

0.2\dimexpr\textheight-6\arrayrulewidth-\topskip\relax

Shortly speaking, how to fix it? What is the correct expression?

9

The algorithm of setting \topskip is applied twice by package longtable. Its output routine takes the material from the current vertical list including \topskip in a box and reinserts it to the now empty vertical list triggering the \topskip setting again. Usually nothing is inserted in the latter case, because the height of the re-inserted box is usually \topskip (because of the former \topskip setting). Thus the contribution of the outer \topskip is 0pt then.

The duplicate \topskip setting complicates counteractions.

Variant a)

\begin{document}
\null % = \hbox{}, triggers full \topskip
\vskip-\topskip % remove \topskip
\vskip-\LTpre %
% \LTpre would be dropped at the start of a fresh page, but
% there is already material (empty box)
\begin{longtable}{...}...\end{longtable}

And the calculation is done without \topskip:

0.2\dimexpr\textheight-6\arrayrulewidth\relax

Also the table should be large enough, to overcompensate the negative spaces. Otherwise the outer \tabskip could become effective.

Variant b)

This sets the value of \topskip to zero temporarily (then \topskip does not matter in the calculation):

\begin{document}
  \begingroup
    \setlength{\topskip}{0pt}
    \begin{longtable}{...}...\end{longtable}
  \endgroup
\end{document}

The result in both cases:

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.