% @stylefile{Super tabular
% shortpackagename = {supertab},
% longpackagename  = {supertabular},
% baseformats      = {\LaTeX 2.09},
% version          = {3.6a},
% date             = {1991-02-15},
% author           = {Theo Jurriens,
%                     TAJ@HGRRUG5,
%                     P.O Box 800,
%                     9700 AV Groningen},
% abstract         = {This file provides the supertabular environment, which
%                     is an extension to the standard tabular environment.
%                     Large tabulars are automatically split across pages.
%                     Seperate commands for the table-head and table-tail
%                     are provided, in order to repeat these on each page.}
% infauthor        = {Johannes Braams,
%                     JL_Braams@pttrnl.nl,
%                     PTT Research,
%                     P.O. Box 421,
%                     2260 AK Leidschendam}
% infdate           = {1990-10-16}}
%
%----------------------------------------------------------------------------
%
% supertabular sty
% original idea:  Theo Jurriens 1988
%                 TAJ@hgrrug5        P.O Box 800, 9700 AV Groningen
%
% revised by:     Johannes Braams
%                 JL_Braams@pttrnl.nl   PTT Research Leidschendam (NL)
%
% 15.02.91  - Because of the check for the use of tablefirsthead the
% V 3.6a      combination of an \hline in the head and an \hline as the first
%             thing in the data went wrong. The \futurelet in the definition
%             of \hline found \fi instead of \hline, so no \doublerulesep
%             was added.
%             Also had to modify the way the environments were defined.
%             The blank space (from the CR after the argument of \supertabular)
%             has to be gobbled. This can only be done using a construction
%             like \def\command#1 {...}. So removed the use of \newenvironment
% 04.02.91  - Added the commands \topcaption, \bottomcaption and \tablecaption
% V 3.6       to include a caption within the supertabular environment. The
%             default behaviour is to put the caption before the actual start
%             of the table.
%           - Also added \tablefirsthead and \tablelasttail to let the
%             user specify a different head for the first page of the table
%             and for consecutive pages as well as different tails for first
%             pages and the last one. If these commands are not used, the
%             default behaviour will be to use the value of \tablehead end
%             \tabletail
%           - Removed the need for the \noalign{\global\let\\=\@stabularcr}
%             commands by storing and resetting \@stabularcr
%
% 16.10.90  Added the supertabular* environment that was in an earlier
% V 3.5     version (2.0) by the original author
%           Reintroduced the version numbering
%
% revised by:     Gabriele Kruljac
%                 kruljac@ds0mpi11   Max-Planck-Institute Stuttgart
%
%
% 06.06.89  Correction: now care is taken of probably existing onecolumn
%           head (title or tables ...) in twocolumn sty.
%
% 10.05.89  Correction: the new \\ definition has been added to the
%           begin of each `sub'-tabular
%           Added: algorithm to produce the tabulars in twocolumn style
%
% 06.04.89  Correction: put \global statement in \end{supertabular}
%           into \noalign
%
% 22.02.89  Correction: restore the original meaning of \\ with
%           \end{supertabular}
%
% (Feb 89) The whole algorithm has been changed, so that I can use
%          the most features of a normal tabular:
%          \\  for new line, including  \\[#1]
%          p{...} in the preamble ...
%          Account is taken to \baselinestretch and \arraystretch
%         -I'm not counting the lines because of too much rounding errors
%          but instead I add the (estimated) used space in pt.
%         -The tablehead is taken into this algorithm of proofing, so
%          I really know how much space the head uses.
%         -When no p-arg is given I add a variable \midlineheight to
%          calculate the used space. To calculate \midlineheight I
%          take the \baselineskip, which is active when the supertabular
%          starts (\baselineskip includes the \value of \baselinestretch)
%          and multiply it with \arraystretch.
%         -When a p-arg is given the text will be stored in a box. So
%          I know the height I have to add. Also I reduce the maximum
%          pagesize, so that the last parbox on a page can get up to
%          max 4 lines without producing an overfull vbox.
%         -To do so I had to make some additions to LaTeX's tabular
%          commands. These new commands got a leading `s'.
%
%          Weak points:
%          -When the material of a normal entry (not a p-arg) becomes
%           larger than the estimated \midlineheight, overfull vboxes
%           will be produced at all.
%          -When the last p-arg on a page gets more than 4 lines
%           (probably even more than 3 lines) it will result in an
%           overfull vbox.
%           Also some combinations of \baselinestretch \arraystretch and
%           a large font may lead to one line too much.
%          -if accidentally the last line of the tabular produces
%           a newpage, on the next page the tabletail will be written
%           immediately after the tablehead. Depending on the contents
%           this may result in an error message regarding misplaced
%           \noalign.
%
%           A quick but not very elegant solution: shrink \maxsize by
%           \noalign{\global\maxsize=...pt} after the first \\ of the
%           supertabular.
%
%------------------------------------------------------------------------------
% Added the user-commands \topcaption and \bottomcaption which set the boolean
% @topcaption to determine where to put the tablecaption. The default
% is to put the caption on the top of the table
%
\newif\if@topcaption \@topcaptiontrue
\def\topcaption{\@topcaptiontrue\tablecaption}
\def\bottomcaption{\@topcaptionfalse\tablecaption}
%
% Added the command \tablecaption, with the use of the definition
% of the \caption and \@caption commands from latex.tex.
% This command has to function exactly like \caption does except it
% has to store its argument (and the optional argument) for later
% processing WITHIN the supertabular environment
% JB
%
\long\def\tablecaption{\refstepcounter{table} \@dblarg{\@xtablecaption}}
\long\def\@xtablecaption[#1]#2{%
  \long\def\@process@tablecaption{\@stcaption{table}[#1]{#2}}}
\let\@process@tablecaption\relax
 
%
% This is a redefinition of LaTeX's \@caption, \@makecaption is
% called within a group so as not to return to \normalsize globally.
% also a fix is made for the `feature' of the \@makecaption of article.sty and
% friends that a caption ALWAYS gets a \vskip 10pt at the top and NONE at the
% bottom. If a user wants to precede his table with a caption this results
% in a collision.
%
\long\def\@stcaption#1[#2]#3{\par%
    \addcontentsline{\csname ext@#1\endcsname}{#1}%
        {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}
  \begingroup
    \@parboxrestore
    \normalsize
    \if@topcaption \vskip -10pt \fi % 'fix'
    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
    \if@topcaption \vskip 10pt \fi % 'fix'
  \endgroup}
 
                             % \tablehead activates the new tabular \cr
                             % commands
\def\@tablehead{}
\def\tablehead#1{\gdef\@tablehead{#1}}
\def\tablefirsthead#1{\gdef\@table@first@head{#1}}
 
%+
%     If the user uses an extra amount of tabular-data (like \multicolumn)
%     in \verb=\tabletail= \TeX\ starts looping because of the definition
%     of \verb=\nextline=. So make \verb=\\= act like just a \verb=\cr=
%     inside this tail to prevent the loop.
%     Save and restore the value of \verb=\\=
%-
\def\@tabletail{}
\def\tabletail#1{%
    \gdef\@tabletail{\noalign{\global\let\@savcr=\\\global\let\\=\cr}%
                     #1\noalign{\global\let\\=\@savcr}}}
\def\tablelasttail#1{\gdef\@table@last@tail{#1}}
 
\newdimen\maxsize            % maximum pagesize
\newdimen\actsize            % actual pagesize
\newdimen\twocolsize         % needed for correct max height if twocolumn
\newdimen\parboxheight       % height plus depth of a parbox-argument
\newdimen\addspace           % stores the value of \\[#1]
\newdimen\midlineheight      % estimated size of a normal line
\newdimen\pargcorrection     % to set page height tolerance if p-arg
\newdimen\computedimens      % computation variable
\newbox\tabparbox
 
         %%%%  Redefine original LaTeX tabular \cr commands. %%%%
         %%%%  New tabular \cr commands get a leading `s'    %%%%
 
                             % Insert  \nextline command for counting
\def\@stabularcr{{\ifnum0=`}\fi\@ifstar{\@sxtabularcr}{\@sxtabularcr}}
\def\@sxtabularcr{\@ifnextchar[{\@sargtabularcr}%
                 {\ifnum0=`{\fi}\cr\nextline}}
 
                             % contents of command unchanged
\def\@sargtabularcr[#1]{\ifnum0=`{\fi}\ifdim #1>\z@
    \unskip\@sxargarraycr{#1}\else \@syargarraycr{#1}\fi}
 
                             % here copy the value #1 of [ ] of \\
                             % to \addspace
\def\@sxargarraycr#1{\@tempdima #1\advance\@tempdima \dp \@arstrutbox%
    \vrule \@height\z@ \@depth\@tempdima \@width\z@ \cr%
    \noalign{\global\addspace=#1}\nextline}
 
                             % command will be called when \\[0pt]
\def\@syargarraycr#1{\cr\noalign{\vskip #1\global\addspace=#1}\nextline}
 
         %%%%  Redefine original LaTeX p-arg commands.       %%%%
         %%%%  New commands get a leading `s'                %%%%
 
                                      % reduce maximum pagesize to have
                                      % a small tolerance for last entry
\def\@sstartpbox#1{\global\advance\maxsize by -\pargcorrection
                   \global\pargcorrection=0pt
                                      % put text into box to save height
                   \setbox\tabparbox%
                          \vtop\bgroup\hsize#1\@arrayparboxrestore}
 
\def\@sendpbox{\par\vskip\dp\@arstrutbox\egroup%
               \computedimens=\ht\tabparbox%
               \advance\computedimens by \dp\tabparbox%
               \ifnum\parboxheight<\computedimens
                  \global\parboxheight=\computedimens
               \fi
               \computedimens=0pt
               \box\tabparbox\hfil}
 
         %%%%  Here start really new supertabular commands   %%%%
 
                                 % estimate height of normal line
                                 % regarding \array- and \baselinestretch
\def\calmidlineheight{\midlineheight=\arraystretch \baslineskp
                      \global\advance\midlineheight by 1pt
                      \global\pargcorrection=4\midlineheight}
 
\def\calpage{\global\actsize=\pagetotal  % where am I on the actual page?
             \twocolsize=\textheight            %  added 06.06.89
             \advance\twocolsize by -\@colroom  %        "
             \advance\actsize by \twocolsize    %        "
             \global\advance\actsize by \midlineheight
             \maxsize=\textheight        % start a new page when 90% of
             \multiply \maxsize by 9     % the page are used
             \divide\maxsize by 10
             \ifnum\actsize > \maxsize
                   \clearpage
                   \global\actsize=\pagetotal
             \fi
             \maxsize=\textheight       % now set \maxsize with tolerance
             \global\advance\maxsize by -\midlineheight}   % of one lines
                             % Here is the definition of supertabular
% modified JB (15.2.91)
\def\supertabular#1 {%           % before it was \edef\tableformat,
                                 % but gave error with @{\hspace{..}} !
    \def\tableformat{\string#1} % store preamble
    \global\starfalse % remember this is the normal version
 
                                 % Check if we have to insert a caption
    \if@topcaption\@process@tablecaption
    \fi
 
    \def\baslineskp{\baselineskip}
    \calmidlineheight% estimate height of a normal line
    \calpage         % calculate max. pagesize and startpoint
 
                                 % save old \@tabularcr
    \let\@@tabularcr\@tabularcr%             Added JB 4/2/91
                                % Now insert the definition of \@stabularcr
    \let\@tabularcr\@stabularcr
                                 % save old \\
    \global\let\@oldcr=\\
 
                                 % activate new parbox algorithm
    \let\@@startpbox=\@sstartpbox
    \let\@@endpbox=\@sendpbox
%
%    Moved the check for the use of \tablefirsthead to befor the start of
%    the tabular environment in order to make the \futurelet inside \hline
%    do its work correctly (15.02.91)
%
    \ifx\@table@first@head\undefined
        \let\@@tablehead=\@tablehead
    \else
        \let\@@tablehead=\@table@first@head
    \fi%                                     Added JB 4/2/91
                                 % start normal tabular environment
    \begin{tabular}{\tableformat}%
    \@@tablehead}%   Added JB 15/2/91
 
                                 % this is \end{supertabular}
\def\endsupertabular{%
    \ifx\@table@last@tail\undefined%
        \@tabletail%
    \else%
        \@table@last@tail%
    \fi%                                     Added JB 4/2/91
%removed JB                \noalign{\global\let\\=\@oldcr}%
%   \let\@@startpbox=\@startpbox%
%   \let\@@endpbox=\@endpbox%
    \end{tabular}
                                 % restore old \@tabularcr
    \let\@tabularcr\@@tabularcr             % Added JB 4/2/91
                                 % Check if we have to insert a caption
    \if@topcaption
    \else
        \@process@tablecaption
                                 % resore to default behaviour
        \@topcaptiontrue
    \fi
%+
%    Restore the meaning of \verb=\\= to the one it had before the start
%    of this environment. Also re-initialize some control-sequences
%-
    \global\let\\=\@oldcr
    \let\@table@first@head\undefined        % For the next ocurrence
    \let\@table@last@tail\undefined         % of this environment
    \let\@process@tablecaption\relax
}
 
                             % Here is the definition of supertabular*
\newif\ifstar
\newdimen\tabularwidth
\@namedef{supertabular*}#1#2 {% modified JB (15.2.91)
                                 % before it was \edef\tableformat,
                                 % but gave error with @{\hspace{..}} !
    \def\tableformat{\string#2} % store preamble
    \tabularwidth=#1 % The total width of the tabular
    \global\startrue % remember this is the *-version
 
                                 % Check if we have to insert a caption
    \if@topcaption\@process@tablecaption\fi
 
    \def\baslineskp{\baselineskip}
    \calmidlineheight% estimate height of a normal line
    \calpage         % calculate max. pagesize and startpoint
 
 
                                 % save old \@tabularcr
    \let\@@tabularcr\@tabularcr%              Added JB 4/2/91
                                % Now insert the definition of \@stabularcr
    \let\@tabularcr\@stabularcr%              Added JB 4/2/91
                                 % save old \\
    \global\let\@oldcr=\\
 
                                 % activate new parbox algorithm
    \let\@@startpbox=\@sstartpbox
    \let\@@endpbox=\@sendpbox
%
%    The same modification as for \tabular 15.2.91
    \ifx\@table@first@head\undefined
        \let\@@tablehead\@tablehead
    \else
        \let\@@tablehead\@table@first@head
    \fi%                                     Added JB 4/2/91
                                 % start normal tabular environment
    \begin{tabular*}{\tabularwidth}{\tableformat}%
%
%removed JB                \noalign{\global\let\\=\@stabularcr}
    \@@tablehead}%
                                 % this is \end{supertabular*}
\@namedef{endsupertabular*}{%
    \ifx\@table@last@tail\undefined%
        \@tabletail%
    \else%
        \@table@last@tail%
    \fi%                                     Added JB 4/2/91
%removed JB                \noalign{\global\let\\=\@oldcr}%
    \end{tabular*}
                                 % restore old \@tabularcr
    \let\@tabularcr\@@tabularcr
%               \let\@@startpbox=\@startpbox%
%               \let\@@endpbox=\@endpbox%
                                 % Check if we have to insert a caption
    \if@topcaption
    \else
        \@process@tablecaption
                                 % resore to default behaviour
        \@topcaptiontrue
    \fi
%+
%    Restore the meaning of \verb=\\= to the one it had before the start
%    of this environment. Also re-initialize some control-sequences
%-
    \global\let\\=\@oldcr
    \let\@table@first@head\undefined        % For the next ocurrence
    \let\@table@last@tail\undefined         % of this environment
    \let\@process@tablecaption\relax}
 
\def\nextline{%           %%% algorithm to calculate the pagebreaks %%%
    \noalign{\ifnum\parboxheight=0
                                 % if no p-arg add `normal' line height
                   \advance\actsize by \midlineheight
                                      % \addspace is value #1 of \\[#1]
                   \global\advance\actsize by \addspace
             \else
                                 % if p-arg add height of box and more
                   \global\advance\actsize by \parboxheight
                   \divide\parboxheight by 11\relax
                   \global\advance\actsize by \parboxheight%
                   \global\parboxheight=0pt
             \fi
             \global\addspace=0pt}%
                                      % when page becomes full:
    \ifnum\actsize<\maxsize
%
%    This line is necessary because the tablehead has to be inserted *after*
%    the \if\else\fi-clause. For this purpose \next is used. In the middle
%    of tableprocessing it shoud be an *empty* macro (*not* \relax).
%    (15.2.91)
    \noalign{\global\let\next\@empty}
    \else
                                      % output \tabletail, close tabular
                                      % output all material and start a
                                      % fresh new page
         \@tabletail
         \ifstar%                     % Added 16-10-90
           \end{tabular*}%
         \else%
           \end{tabular}%
         \fi
         \if@twocolumn%                        % added 10.05.89
            \if@firstcolumn%                   %
               \newpage%                       %
            \else%                             %
               \clearpage%                     %
            \fi%                               %
            \twocolsize=\textheight%           % added 06.06.89
            \advance\twocolsize by -\@colroom% %       "
            \global\actsize=\twocolsize%       %       "
         \else                                 %
            \clearpage                         %
            \global\actsize=\midlineheight%
         \fi                                   %
         \let\next\@tablehead%                 % Added 15.2.91
         \ifstar%                              % Added 16-10-90
           \begin{tabular*}{\tabularwidth}{\tableformat}%
         \else%
           \begin{tabular}{\tableformat}%
         \fi%
%removed JB         \noalign{\global\let\\=\@stabularcr}  % added 10.05.89
%removed JB         \@tablehead%
    \fi\next}%                                % Added \next 15.2.91
