1

I am trying to design a title page macro with several equally spaced parts. One of those part contains a longtable table. When I include the table, some of the \vfill commands no longer seem to expand to equalize the spacing. I'm hoping someone here can see something I'm not seeing here.

Here is my MWE:

\documentclass{article}

\usepackage{array}
\usepackage{longtable}
\usepackage{calc}

\begin{document}

% A bit less than half the page width
\newlength{\halfwd}
\setlength{\halfwd}{((\textwidth) * \real{0.95} - \columnsep)/2}%

% A longtable that I want as one of the page components
\def\lt{%
  \setlength\extrarowheight{12pt}%
  \begin{longtable}{p{\halfwd}p{\halfwd}}%
    \parbox[t]{\halfwd}{%
    11111111111111111111\\
    11111111111111111111\\
    11111111111111111111}&
    \parbox[t]{\halfwd}{22222222222222222222\\
    22222222222222222222\\
    22222222222222222222}\\

    \parbox[t]{\halfwd}{33333333333333333333\\
    33333333333333333333\\
    33333333333333333333}&
    \parbox[t]{\halfwd}{44444444444444444444\\
    44444444444444444444\\
    44444444444444444444}\\

    \parbox[t]{\halfwd}{55555555555555555555\\
    55555555555555555555\\
    55555555555555555555}&
    \parbox[t]{\halfwd}{66666666666666666666\\
    66666666666666666666\\
    66666666666666666666}\\
  \end{longtable}
}

% I expect each part of the page to be equally spaced and all the parts together
% to fill up the whole page.
  \begin{center}
    \hrule
    Part I
    \vfill
    \hrule
    \vfill
    Part II
    \vfill
    \hrule
    \vfill
    Part III
    {\texttt \lt}
    \vfill
    \hrule
    \vfill
    Part IV
    \vfill
    \hrule
  \end{center}
\end{document}

Here is what the output looks like. Parts I and II get squished to minimal size, while it seems all Parts ought to be of equally spaced-out.

Imgur

11
  • A longtable in a context which is only on one page is nonsense. Why don't you use a simple tabular? Commented Sep 13, 2017 at 9:47
  • Beside this you naturally need some \par (empty lines) if you want to use \vfill this way. And use \ttfamily instead of \texttt. Commented Sep 13, 2017 at 9:51
  • why do you have \parboxes nested inside parboxes and also there is no need to guess .95 scalefactor (you are relying on .95\textwidth+4\tabcolsep being \textwidth which is not usually true) Commented Sep 13, 2017 at 10:19
  • The partial page above a longtable is boxed (thus forcing glue to its natural length, 0 on the case of \vfil in order to allow longtable to know how big its first page needs to be, it would require quite a lot of code to do anything else, but you don't need longtable if it is just two parboxes per line. All entries are fixed width so will align anyway there is no need for a table. Commented Sep 13, 2017 at 10:33
  • David, you're right. I didn't see that the longtable attributes duplicate the parboxes in the body. Thanks. The width is just to leave some margin on both sides, not assuming any relationship to \tabcolsep. Commented Sep 13, 2017 at 10:37

2 Answers 2

1

You can avoid longtable boxing the content of the page-so-far and so freezing the vertical skips at their natural width of 0pt by removing a \vbox as follows:

enter image description here

\documentclass{article}

\usepackage{array}
\usepackage{longtable}
\usepackage{calc}
\makeatletter
\def\LT@output{%
  \ifnum\outputpenalty <-\@Mi
    \ifnum\outputpenalty > -\LT@end@pen
      \LT@err{floats and marginpars not allowed in a longtable}\@ehc
    \else
      \setbox\z@\vbox{\unvbox\@cclv}%
      \ifdim \ht\LT@lastfoot>\ht\LT@foot
        \dimen@\pagegoal
        \advance\dimen@-\ht\LT@lastfoot
        \ifdim\dimen@<\ht\z@
          \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}%
          \@makecol
          \@outputpage
          \setbox\z@\vbox{\box\LT@head}%
        \fi
      \fi
      \global\@colroom\@colht
      \global\vsize\@colht
%      \vbox
        {\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}%
    \fi
  \else
    \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
    \@makecol
    \@outputpage
      \global\vsize\@colroom
    \copy\LT@head\nobreak
  \fi}

\begin{document}

% A bit less than half the page width
\newlength{\halfwd}
\setlength{\halfwd}{((\textwidth) * \real{0.95} - \columnsep)/2}%

% A longtable that I want as one of the page components
\def\lt{%
  \setlength\extrarowheight{12pt}%
  \begin{longtable}{p{\halfwd}p{\halfwd}}%
    \parbox[t]{\halfwd}{%
    11111111111111111111\\
    11111111111111111111\\
    11111111111111111111}&
    \parbox[t]{\halfwd}{22222222222222222222\\
    22222222222222222222\\
    22222222222222222222}\\

    \parbox[t]{\halfwd}{33333333333333333333\\
    33333333333333333333\\
    33333333333333333333}&
    \parbox[t]{\halfwd}{44444444444444444444\\
    44444444444444444444\\
    44444444444444444444}\\

    \parbox[t]{\halfwd}{55555555555555555555\\
    55555555555555555555\\
    55555555555555555555}&
    \parbox[t]{\halfwd}{66666666666666666666\\
    66666666666666666666\\
    66666666666666666666}\\
  \end{longtable}
}

% I expect each part of the page to be equally spaced and all the parts together
% to fill up the whole page.
  \begin{center}
    \hrule
    Part I
    \vfill
    \hrule
    \vfill
    Part II
    \vfill
    \hrule
    \vfill
    Part III
    {\texttt \lt}
    \vfill
    \hrule
    \vfill
    Part IV
    \vfill
    \hrule
  \end{center}
\end{document}
1
  • Whoa. Nice! That actually solves it. Thanks David! Commented Sep 13, 2017 at 11:06
1

I don't know what layout you really have in mind. But with a few empty lines, tabular instead of longtable and \ttfamily one gets something that looks more or less sensible:

\documentclass{article}

\usepackage{array}
\usepackage{longtable}
\usepackage{calc}

\begin{document}

% A bit less than half the page width
\newlength{\halfwd}
\setlength{\halfwd}{((\textwidth) * \real{0.95} - \columnsep)/2}%

% A longtable that I want as one of the page components
\def\lt{%
  \setlength\extrarowheight{12pt}%
  \begin{tabular}{ll}%
    \parbox[t]{\halfwd}{%
    11111111111111111111\\
    11111111111111111111\\
    11111111111111111111}&
    \parbox[t]{\halfwd}{22222222222222222222\\
    22222222222222222222\\
    22222222222222222222}\\

    \parbox[t]{\halfwd}{33333333333333333333\\
    33333333333333333333\\
    33333333333333333333}&
    \parbox[t]{\halfwd}{44444444444444444444\\
    44444444444444444444\\
    44444444444444444444}\\

    \parbox[t]{\halfwd}{55555555555555555555\\
    55555555555555555555\\
    55555555555555555555}&
    \parbox[t]{\halfwd}{66666666666666666666\\
    66666666666666666666\\
    66666666666666666666}\\
  \end{tabular}}

% I expect each part of the page to be equally spaced and all the parts together
% to fill up the whole page.
  \begin{center}
    \hrule
    \vfill 

    Part I

    \vfill
    \hrule
    \vfill
    Part II

    \vfill
    \hrule
    \vfill
    Part III

    {\ttfamily \lt}

    \vfill
    \hrule
    \vfill
    Part IV

    \vfill
    \hrule
  \end{center}
\end{document}

enter image description here

4
  • Ulrike, thanks for the suggestions. The longtable construct here may appear other places besides the title page and may, though it usually does not, take more than one page. Since I don't know in advance how many \parbox elements will need to be displayed, I use longtable so that it can handle either case. Using tabular will not work when the number of \parbox elements is large. Do you see any way to get the effect you show while still using the longtable environment? Commented Sep 13, 2017 at 10:21
  • As you are using fix width boxes as cells anyway I don't really see why you use a tabular at all. Commented Sep 13, 2017 at 10:33
  • Ulrike, in actual practice, they are not fixed width. They are name and address blocks for use in a legal brief. Commented Sep 13, 2017 at 10:48
  • Ulrike, I am accepting your answer. With your answer and @DavidCarlise's comments above, I believe I understand what's going on now. Thanks. Commented Sep 13, 2017 at 11:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .