%%
%% This is file `xtab.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xtab.dtx  (with options: `xtab')
%% 
%%  Copyright 1998 Peter R. Wilson
%% 
%%  This program is provided under the terms of the
%%  LaTeX Project Public License distributed from CTAN
%%  archives in directory macros/latex/base/lppl.txt.
%% 
%% Author: Peter Wilson (CUA and NIST)
%%         now at peter.r.wilson@boeing.com
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{xtab}[1998/04/13 v2 Extended supertabular package]
\newcount\c@tracingst
\DeclareOption{errorshow}{\c@tracingst\z@}
%%%%\DeclareOption{pageshow}{\c@tracingst\tw@}
\DeclareOption{pageshow}{\c@tracingst\thr@@}
\DeclareOption{debugshow}{\c@tracingst5\relax}
\ProcessOptions
\newif\if@topcaption \@topcaptiontrue
\def\topcaption{\@topcaptiontrue\tablecaption}
\def\bottomcaption{\@topcaptionfalse\tablecaption}
\gdef\PWST@thecaption{}
\newdimen\PWSTcapht
\long\def\tablecaption{%
  \refstepcounter{table}\@dblarg{\@xtablecaption}}
\long\def\@xtablecaption[#1]#2{%
  \long\gdef\PWST@thecaption{#2}%
  \long\gdef\@process@tablecaption{\ST@caption{table}[#1]{#2}}}
\global\let\@process@tablecaption\relax
\newif\ifST@star
\newif\ifST@mp
\newdimen\ST@wd
\newskip\ST@rightskip
\newskip\ST@leftskip
\newskip\ST@parfillskip
\long\def\ST@caption#1[#2]#3{\par%
  \addcontentsline{\csname ext@#1\endcsname}{#1}%
                  {\protect\numberline{%
                    \csname the#1\endcsname}{\ignorespaces #2}}
  \begingroup
    \@parboxrestore
    \normalsize
    \if@topcaption \vskip -10\p@ \fi
    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
    \if@topcaption \vskip 10\p@ \fi
  \endgroup}
\@ifundefined{iftabs}{%
  \newif\iftabs}{}
\ifx\rectoisotitlehead\undefined\else
  \typeout{xtab using iso captions}
  \long\def\ST@caption#1[#2]#3{\par%
    \iftabs\else\tabstrue
      \if@filesw\immediate\write\@mainaux{%
        \string\gdef\string\settabs{%
          \string\floatlist{\listtablename}{lot}}}
      \fi
    \fi
    \addcontentsline{\csname ext@#1\endcsname}{#1}%
                    {\protect\numberline{%
                        \csname the#1\endcsname}{\ignorespaces #2}}
    \begingroup
      \@parboxrestore
      \normalsize
      \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
      \if@topcaption \vskip -10pt \fi
    \endgroup}
\fi
\newcommand\tablehead[1]{%
  \gdef\@tablehead{%
  \noalign{%
    \global\let\@savcr=\\
    \global\let\\=\org@tabularcr}%
  #1%
  \noalign{\global\let\\=\@savcr}}}
\tablehead{}
\newcommand\tablefirsthead[1]{\gdef\@table@first@head{#1}}
\newcounter{PWSTtable}
\newcount\PWSTlastpage
\newcount\PWSTpenultimate
\newcount\PWSTcurpage
\newcount\PWSTtempc
\newcount\PWSTlines
\newcount\PWSThead
\newcount\PWSTlasthead
\newif\iffirstcall
\newdimen\PWST@lastht
\newdimen\PWST@generalht
\newdimen\PWST@ht
\newcommand{\tablelasthead}[1]{\gdef\@table@last@head{#1}}
\newcommand{\notablelasthead}{\let\@table@last@head\relax}
\tablelasthead{}
\notablelasthead
\newcommand\tabletail[1]{%
  \gdef\@tabletail{%
    \noalign{%
      \global\let\@savcr=\\
      \global\let\\=\org@tabularcr}%
    #1%
    \noalign{\global\let\\=\@savcr}}}
\tabletail{}
\newcommand\tablelasttail[1]{\gdef\@table@last@tail{#1}}
\tablelasttail{}
\newcommand\sttraceon{\c@tracingst5\relax}
\newcommand\sttraceoff{\c@tracingst\z@}
\newcommand\ST@trace[2]{%
  \ifnum\c@tracingst>#1\relax
    \GenericWarning
      {(xtab)\@spaces\@spaces}
      {Package xtab: #2}%
  \fi
}
\newdimen\ST@pageleft
\newcommand*\shrinkheight[1]{%
  \noalign{\global\advance\ST@pageleft-#1\relax}}
\newcommand*\setSTheight[1]{%
  \noalign{\global\ST@pageleft=#1\relax}}
\newdimen\ST@headht
\newdimen\ST@tailht
\newdimen\ST@pagesofar
\newdimen\ST@pboxht
\newdimen\ST@lineht
\newdimen\ST@stretchht
\newdimen\ST@prevht
\newdimen\ST@toadd
\newdimen\ST@dimen
\newbox\ST@pbox
\def\ST@tabularcr{%
  {\ifnum0=`}\fi
  \@ifstar{\ST@xtabularcr}{\ST@xtabularcr}}
\def\ST@xtabularcr{%
  \@ifnextchar[%]
    {\ST@argtabularcr}%
    {\ifnum0=`{\fi}\cr\ST@cr}}
\def\ST@argtabularcr[#1]{%
  \ifnum0=`{\fi}%
  \ifdim #1>\z@
    \unskip\ST@xargarraycr{#1}
  \else
    \ST@yargarraycr{#1}%
  \fi}
\def\ST@xargarraycr#1{%
  \@tempdima #1\advance\@tempdima \dp \@arstrutbox
  \vrule \@height\z@ \@depth\@tempdima \@width\z@ \cr
  \noalign{\global\ST@toadd=#1}\ST@cr}
\def\ST@yargarraycr#1{%
  \cr\noalign{\vskip #1\global\ST@toadd=#1}\ST@cr}
\def\ST@startpbox#1{%
  \setbox\ST@pbox\vtop\bgroup\hsize#1\@arrayparboxrestore}
\def\ST@astartpbox#1{%
  \bgroup\hsize#1%
  \setbox\ST@pbox\vtop\bgroup\hsize#1\@arrayparboxrestore}
\def\ST@endpbox{%
  \@finalstrut\@arstrutbox\par\egroup
  \ST@dimen=\ht\ST@pbox
  \advance\ST@dimen by \dp\ST@pbox
  \ifnum\ST@pboxht<\ST@dimen
    \global\ST@pboxht=\ST@dimen
  \fi
  \ST@dimen=\z@
  \box\ST@pbox\hfil}
\def\ST@aendpbox{%
  \@finalstrut\@arstrutbox\par\egroup
  \ST@dimen=\ht\ST@pbox
  \advance\ST@dimen by \dp\ST@pbox
  \ifnum\ST@pboxht<\ST@dimen
    \global\ST@pboxht=\ST@dimen
  \fi
  \ST@dimen=\z@
  \unvbox\ST@pbox\egroup\hfil}
\def\estimate@lineht{%
  \ST@lineht=\arraystretch \baselineskip
  \global\advance\ST@lineht by 1\p@
  \ST@stretchht\ST@lineht\advance\ST@stretchht-\baselineskip
  \ifdim\ST@stretchht<\z@\ST@stretchht\z@\fi
  \ST@trace\tw@{Average line height: \the\ST@lineht}%
  \ST@trace\tw@{Stretched line height: \the\ST@stretchht}%
}
\def\@calfirstpageht{%
  \ST@trace\tw@{Calculating height of tabular on first page}%
  \global\ST@pagesofar\pagetotal
  \global\ST@pageleft\@colroom
  \ST@trace\tw@{Height of text = \the\pagetotal; \MessageBreak
                Height of page = \the\ST@pageleft}%
  \if@twocolumn
    \ST@trace\tw@{two column mode}%
    \if@firstcolumn
      \ST@trace\tw@{First column}%
      \ifnum\ST@pagesofar > \ST@pageleft
        \global\ST@pageleft=2\ST@pageleft
        \ifnum\ST@pagesofar > \ST@pageleft
          \newpage\@calnextpageht
          \ST@trace\tw@{starting new page}%
        \else
          \ST@trace\tw@{Second column}%
          \global\advance\ST@pageleft -\ST@pagesofar
          \global\advance\ST@pageleft -\@colroom
        \fi
     \else
       \global\advance\ST@pageleft by -\ST@pagesofar
       \global\ST@pagesofar\z@
      \fi
    \else
      \ST@trace\tw@{Second column}%
      \ifnum\ST@pagesofar > \ST@pageleft
        \ST@trace\tw@{starting new page}%
        \newpage\@calnextpageht
      \else
        \global\advance\ST@pageleft by -\ST@pagesofar
        \global\ST@pagesofar\z@
      \fi
    \fi
  \else
     \ST@trace\tw@{one column mode}%
     \ifnum\ST@pagesofar > \ST@pageleft
       \ST@trace\tw@{starting new page}%
     \newpage\@calnextpageht
    \else
      \global\advance\ST@pageleft by -\ST@pagesofar
      \global\ST@pagesofar\z@
    \fi
  \fi
  \ST@trace\tw@{Available height: \the\ST@pageleft}%
  \ifx\@@tablehead\@empty
    \ST@headht=\z@
  \else
    \setbox\@tempboxa=\vbox{\@arrayparboxrestore
      \ST@restore
      \expandafter\tabular\expandafter{\ST@tableformat}%
      \@@tablehead\endtabular}%
    \ST@headht=\ht\@tempboxa\advance\ST@headht\dp\@tempboxa
  \fi
  \ST@trace\tw@{Height of head: \the\ST@headht}%
  \ifx\@tabletail\@empty
    \ST@tailht=\z@
  \else
    \setbox\@tempboxa=\vbox{\@arrayparboxrestore
      \ST@restore
      \expandafter\tabular\expandafter{\ST@tableformat}
        \@tabletail\endtabular}
    \ST@tailht=\ht\@tempboxa\advance\ST@tailht\dp\@tempboxa
  \fi
  \advance\ST@tailht by \ST@lineht
  \ST@trace\tw@{Height of tail: \the\ST@tailht}%
  \ST@trace\tw@{Maximum height of tabular: \the\ST@pageleft}%
  \@tempdima\ST@headht
  \advance\@tempdima\ST@lineht
  \advance\@tempdima\ST@tailht
  \if@topcaption
    \setbox\@tempboxa=\vbox{\PWST@thecaption}
    \PWSTcapht=\ht\@tempboxa\advance\PWSTcapht\dp\@tempboxa
    \advance\PWSTcapht by 20\p@
  \else
    \PWSTcapht = 10\p@
  \fi
  \ST@trace\tw@{Caption height: \the\PWSTcapht}%
  \advance\@tempdima\PWSTcapht
  \ST@trace\tw@{Minimum height of tabular: \the\@tempdima}%
  \ifnum\@tempdima>\ST@pageleft
    \ST@trace\tw@{starting new page}%
    \newpage
    \global\ST@pageleft\@colroom
    \global\advance\ST@pageleft by -\PWSTcapht
    \global\ST@pagesofar=\z@
  \fi
}
\def\@calnextpageht{%
  \ST@trace\tw@{Calculating height of tabular on next page}%
  \global\ST@pageleft\@colroom
  \global\ST@pagesofar=\z@
  \ST@trace\tw@{Maximum height of tabular: \the\ST@pageleft}%
  }
\newcommand{\PWSTcalchtlines}{%
  \setbox\@tempboxa=\vbox{\@arrayparboxrestore
    \ST@restore
    \expandafter\tabular\expandafter{\ST@tableformat}%
    \@table@last@tail\endtabular}%
  \PWST@ht=\ht\@tempboxa\advance\PWST@ht\dp\@tempboxa
  \global\PWST@lastht = \PWST@ht
  \PWSTlines = \PWST@ht
  \divide\PWSTlines by \baselineskip
  \global\PWSTlasthead = \PWSTlines
  \global\PWSThead = \PWSTlasthead
  \setbox\@tempboxa=\vbox{\@arrayparboxrestore
    \ST@restore
    \expandafter\tabular\expandafter{\ST@tableformat}%
    \@table@last@head\endtabular}%
  \PWST@ht = \ht\@tempboxa\advance\PWST@ht\dp\@tempboxa
  \global\advance\PWST@lastht by \PWST@ht
  \ST@trace\tw@{Height of last empty table = \the\PWST@lastht}%
  \PWSTlines = \PWST@ht
  \divide\PWSTlines by \baselineskip
  \global\advance\PWSTlasthead by \PWSTlines
  \global\advance\PWSTlasthead \@ne
  \ST@trace\tw@{Number of lines + 1 in last empty table = \the\PWSTlasthead}%
  \setbox\@tempboxa=\vbox{\@arrayparboxrestore
    \ST@restore
    \expandafter\tabular\expandafter{\ST@tableformat}%
    \@tabletail\endtabular}%
  \PWST@ht=\ht\@tempboxa\advance\PWST@ht\dp\@tempboxa
  \global\PWST@generalht = \PWST@ht
  \setbox\@tempboxa=\vbox{\@arrayparboxrestore
    \ST@restore
    \expandafter\tabular\expandafter{\ST@tableformat}%
    \@tablehead\endtabular}%
  \PWST@ht = \ht\@tempboxa\advance\PWST@ht\dp\@tempboxa
  \global\advance\PWST@generalht by \PWST@ht
  \ST@trace\tw@{Height of general empty table = \the\PWST@generalht}%
  \PWSTlines = \PWST@ht
  \divide\PWSTlines by \baselineskip
  \global\advance\PWSThead by \PWSTlines
  \global\advance\PWSThead \@ne
  \ST@trace\tw@{Number of lines + 1 in general empty table = \the\PWSThead}%
}
\newcommand{\PWSTcalnextpageht}{%
  \ifnum\PWSTcurpage = \PWSTpenultimate
    \ST@trace\tw@{Calculating height of tabular on last page}%
    \PWST@ht=\PWST@lastht
  \else
    \ST@trace\tw@{Calculating height of tabular on next general page}%
    \PWST@ht=\PWST@generalht
  \fi
  \global\ST@pageleft\@colroom
  \global\advance\ST@pageleft -\PWST@ht
  \global\ST@pagesofar=\z@
  \ST@trace\tw@{Maximum height of tabular: \the\ST@pageleft}%
}
\def\x@supertabular{%
  \let\org@tabular\tabular
  \let\tabular\inner@tabular
  \expandafter\let
    \csname org@tabular*\expandafter\endcsname
    \csname tabular*\endcsname
  \expandafter\let\csname tabular*\expandafter\endcsname
    \csname inner@tabular*\endcsname
%%%%  \if@topcaption \@process@tablecaption \fi
  \global\let\@oldcr=\\
  \def\baslineskp{\baselineskip}%
  \ifx\undefined\@classix
    \let\org@tabularcr\@tabularcr
    \let\@tabularcr\ST@tabularcr
    \let\org@startpbox=\@startpbox
    \let\org@endpbox=\@endpbox
    \let\@@startpbox=\ST@startpbox
    \let\@@endpbox=\ST@endpbox
  \else
    \let\org@tabularcr\@arraycr
    \let\@arraycr\ST@tabularcr
    \let\org@startpbox=\@startpbox
    \let\org@endpbox=\@endpbox
    \let\@startpbox=\ST@astartpbox
    \let\@endpbox=\ST@aendpbox
  \fi
  \ifx\@table@first@head\undefined
    \let\@@tablehead=\@tablehead
  \else
    \let\@@tablehead=\@table@first@head
  \fi
  \let\ST@skippage\ST@skipfirstpart
  \estimate@lineht
  \@calfirstpageht
  \PWSTinit
  \if@topcaption \@process@tablecaption \fi
  \noindent
}
\newcommand{\PWSTinit}{%
  \global\advance\c@PWSTtable\@ne
  \global\expandafter\let\expandafter\PWSTtempc
    \csname PWST@\romannumeral\c@PWSTtable\endcsname
  \ifx\PWSTtempc\relax
    \ST@trace\tw@{Table \the\c@PWSTtable: Processing for the first time}%
    \PWSTlastpage=\@m % = 1000
  \else
    \PWSTlastpage=\PWSTtempc
  \fi
  \ST@trace\tw@{Table \the\c@PWSTtable: last page set to \the\PWSTlastpage}%
  \PWSTcurpage=\@ne
  \PWSTcalchtlines
  \global\PWSTlines=\z@
  \global\firstcalltrue
  \ifx\rectoisotitlehead\undefined\else
    \infloattrue
  \fi
}
\def\xtabular{%
  \@ifnextchar[{\@supertabular}%]
               {\@supertabular[]}}
\def\supertabular{%
  \PackageWarning{xtab}{supertabular is deprecated. Use xtabular instead.}%
  \@ifnextchar[{\@supertabular}%]
               {\@supertabular[]}}
\def\@supertabular[#1]#2{%
  \def\ST@tableformat{#2}
  \ST@trace\tw@{Starting a new supertabular}%
  \global\ST@starfalse
  \global\ST@mpfalse
  \x@supertabular
  \expandafter\org@tabular\expandafter{\ST@tableformat}%
  \@@tablehead}
\@namedef{xtabular*}#1{%
  \@ifnextchar[{\@nameuse{@supertabular*}{#1}}%
               {\@nameuse{@supertabular*}{#1}[]}%]
  }
\@namedef{supertabular*}#1{%
  \PackageWarning{xtab}{supertabular* is deprecated. Use xtabular* instead.}%
  \@ifnextchar[{\@nameuse{@supertabular*}{#1}}%
               {\@nameuse{@supertabular*}{#1}[]}%]
  }
\@namedef{@supertabular*}#1[#2]#3{%
  \ST@trace\tw@{Starting a new supertabular*}%
  \def\ST@tableformat{#3}%
  \ST@wd=#1\relax
  \global\ST@startrue
  \global\ST@mpfalse
  \x@supertabular
  \expandafter\csname org@tabular*\expandafter\endcsname
  \expandafter{\expandafter\ST@wd\expandafter}%
  \expandafter{\ST@tableformat}%
  \@@tablehead}%
\def\mpxtabular{%
  \@ifnextchar[{\@mpsupertabular}%]
               {\@mpsupertabular[]}}
\def\mpsupertabular{%
  \PackageWarning{xtab}{mpsupertabular is deprecated. Use mpxtabular instead.}%
  \@ifnextchar[{\@mpsupertabular}%]
               {\@mpsupertabular[]}}
\def\@mpsupertabular[#1]#2{%
  \def\ST@tableformat{#2}%
  \ST@trace\tw@{Starting a new mpsupertabular}%
  \global\ST@starfalse
  \global\ST@mptrue
  \ST@rightskip \rightskip
  \ST@leftskip \leftskip
  \ST@parfillskip \parfillskip
  \x@supertabular
  \minipage{\columnwidth}%
  \parfillskip\ST@parfillskip
  \rightskip \ST@rightskip
  \leftskip \ST@leftskip
  \noindent\expandafter\org@tabular\expandafter{\ST@tableformat}%
  \@@tablehead}
\@namedef{mpxtabular*}#1{%
  \@ifnextchar[{\@nameuse{@mpsupertabular*}{#1}}%
               {\@nameuse{@mpsupertabular*}{#1}[]}%]
}
\@namedef{mpsupertabular*}#1{%
  \PackageWarning{xtab}{mpsupertabular* is deprecated. Use mpxtabular* instead.}%
  \@ifnextchar[{\@nameuse{@mpsupertabular*}{#1}}%
               {\@nameuse{@mpsupertabular*}{#1}[]}%]
}
\@namedef{@mpsupertabular*}#1[#2]#3{%
  \ST@trace\tw@{Starting a new mpsupertabular*}%
  \def\ST@tableformat{#3}%
  \ST@wd=#1\relax
  \global\ST@startrue
  \global\ST@mptrue
  \ST@rightskip \rightskip
  \ST@leftskip \leftskip
  \ST@parfillskip \parfillskip
  \x@supertabular
  \minipage{\columnwidth}%
  \parfillskip\ST@parfillskip
  \rightskip \ST@rightskip
  \leftskip \ST@leftskip
  \noindent\expandafter\csname org@tabular*\expandafter\endcsname
  \expandafter{\expandafter\ST@wd\expandafter}%
  \expandafter{\ST@tableformat}%
  \@@tablehead}%
\def\endxtabular{%
  \ifx\@table@last@tail\undefined
    \@tabletail
  \else
    \@table@last@tail
  \fi
  \csname endtabular\ifST@star*\fi\endcsname
  \x@endsupertabular
  \ST@trace\tw@{Ended a supertabular\ifST@star*\fi}%
  }
\def\endsupertabular{\endxtabular}
\expandafter\let\csname endxtabular*\endcsname\endxtabular
\expandafter\let\csname endsupertabular*\endcsname\endsupertabular
\newcommand{\x@endsupertabular}{%
  \ST@restore
  \if@topcaption
  \else
    \@process@tablecaption
    \global\@topcaptiontrue
  \fi
  \global\let\\=\@oldcr
  \global\let\@table@first@head\undefined
  \global\let\@table@last@tail\undefined
  \global\let\@process@tablecaption\relax
  \PWSToplastpagenum
  \ifx\rectoisotitlehead\undefined\else
    \infloatfalse
  \fi
}
\newcommand{\PWSToplastpagenum}{%
  \ifnum\PWSTcurpage=\PWSTlastpage
    \iffirstcall  % on last, no overflow
      \ifnum\PWSTlines < \PWSTlasthead % this table is empty
        \global\advance\PWSTcurpage \m@ne
      \fi
    \else % overflow
      \ifnum\PWSTlines > \tw@ % enough for another page
        \global\advance\PWSTcurpage \@ne
      \fi
    \fi
  \else
    \ifnum\PWSTlines < \PWSThead % empty table
      \global\advance\PWSTcurpage \m@ne
    \fi
  \fi
  \if@filesw\immediate\write\@auxout%
    {\gdef\string\PWST@\romannumeral\c@PWSTtable{\the\PWSTcurpage}}
    \ST@trace\tw@{Table \the\c@PWSTtable: wrote \the\PWSTcurpage\space as the last page}%
  \fi
}
\def\endmpxtabular{%
  \ifx\@table@last@tail\undefined
    \@tabletail
  \else
    \@table@last@tail
  \fi
  \csname endtabular\ifST@star*\fi\endcsname
  \endminipage
  \x@endsupertabular
  \ST@trace\tw@{Ended an mpsupertabular\ifST@star*\fi}%
  }
\def\endmpsupertabular{\endmpxtabular}
\expandafter\let\csname endmpxtabular*\endcsname\endmpxtabular
\expandafter\let\csname endmpsupertabular*\endcsname\endmpsupertabular
\def\ST@restore{%
  \ifx\undefined\@classix
    \let\@tabularcr\org@tabularcr
  \else
    \let\@arraycr\org@tabularcr
  \fi
  \let\@startpbox\org@startpbox
  \let\@endpbox\org@endpbox
}
\def\inner@tabular{%
  \ST@restore
  \let\\=\@oldcr
  \noindent
  \org@tabular}
\@namedef{inner@tabular*}{%
  \ST@restore
  \let\\=\@oldcr
  \noindent
  \csname org@tabular*\endcsname}
\def\ST@cr{%
  \noalign{%
    \ST@trace\thr@@{Parbox height: \the\ST@pboxht \space\space Line height: \the\ST@lineht}%
    \ifnum\ST@pboxht<\ST@lineht
      \global\advance\ST@pageleft -\ST@lineht
      \global\ST@prevht\ST@lineht
    \else
      \ST@trace\thr@@{Added par box with height \the\ST@pboxht}%
      \global\advance\ST@pageleft -\ST@pboxht
      \global\advance\ST@pageleft -0.1\ST@pboxht
      \global\advance\ST@pageleft -\ST@stretchht
      \global\ST@prevht\ST@pboxht
      \global\ST@pboxht\z@
    \fi
     \global\advance\ST@pageleft -\ST@toadd
     \global\ST@toadd=\z@
     \ST@trace\thr@@{Space left for tabular: \the\ST@pageleft}%
     \global\advance\PWSTlines \@ne
     \ST@trace\thr@@{Line counter incremented by one to: \the\PWSTlines}%
  } % end of noalign
  \ifnum\PWSTcurpage=\PWSTlastpage
    \PWST@lastpagecr
  \else
    \ifnum\ST@pageleft<\z@
      \ST@skippage
    \else
      \noalign{\global\@tempdima\ST@tailht
        \global\advance\@tempdima\ST@prevht
      \ifST@mp
        \ifvoid\@mpfootins\else
          \global\advance\@tempdima\ht\@mpfootins
          \global\advance\@tempdima 3pt
        \fi
      \fi} % end noalign
      \ifnum\ST@pageleft<\@tempdima
        \ST@newpage
      \else
        \noalign{\global\let\ST@next\@empty}%
      \fi
    \fi
  \fi
  \ST@next}
\newcommand{\PWST@lastpagecr}{%
  \noalign{%
    \ifnum\ST@pageleft<\z@
      \PWST@setfirstcall
    \fi
    \global\@tempdima\ST@tailht
    \global\advance\@tempdima\ST@prevht
      \ifST@mp
        \ifvoid\@mpfootins\else
          \global\advance\@tempdima\ht\@mpfootins
          \global\advance\@tempdima 3pt
        \fi
      \fi
      \ifnum\ST@pageleft<\@tempdima
        \PWST@setfirstcall
      \fi
      \global\let\ST@next\@empty
      } % end noalign
}
\newcommand{\PWST@setfirstcall}{%
  \iffirstcall
    \global\firstcallfalse
    \global\PWSTlines=\z@
    \ST@trace\thr@@{Overflow on last page. Line counter zeroed to \the\PWSTlines}%
  \fi
}
\def\ST@skipfirstpart{%
  \noalign{%
    \ST@trace\tw@{Tabular too high, moving to next page}%
    \global\advance\ST@pageleft\pagetotal
    \global\ST@pagesofar\z@
    \newpage
    \global\let\ST@skippage\ST@newpage
  }
}
\def\ST@newpage{%
  \noalign{\ST@trace\tw@{Starting new page, writing tail}}%
  \@tabletail
  \ifST@star
    \csname endtabular*\endcsname
  \else
    \endtabular
  \fi
  \ifST@mp
    \endminipage
  \fi
  \global\let\ST@skippage\ST@newpage
%%%%  \newpage\@calnextpageht
  \newpage\PWSTcalnextpageht
  \ST@trace\tw@{writing head}%
%%%%  \let\ST@next\@tablehead
  \PWSTsethead
  \ifST@mp
    \noindent\minipage{\columnwidth}%
    \parfillskip\ST@parfillskip
    \rightskip \ST@rightskip
    \leftskip \ST@leftskip
  \fi
  \noindent
  \ifST@star
    \expandafter\csname org@tabular*\expandafter\endcsname
    \expandafter{\expandafter\ST@wd\expandafter}%
    \expandafter{\ST@tableformat}%
  \else
    \expandafter\org@tabular\expandafter{\ST@tableformat}%
  \fi}
\newcommand{\PWSTsethead}{%
  \global\PWSTlines=\z@
  \ST@trace\thr@@{Newpage, line counter zeroed to: \the\PWSTlines}%
  \global\advance\PWSTcurpage\@ne
  \ST@trace\tw@{Table \the\c@PWSTtable: current page = \the\PWSTcurpage,
                                  last page = \the\PWSTlastpage}%
  \ifnum\PWSTcurpage=\PWSTlastpage
    \ST@trace\tw@{Newpage is the last page}%
    \ifnum\PWSTcurpage>\@ne
      \ifx\@table@last@head\relax
        \let\ST@next\@tablehead
        \ST@trace\tw@{Set heading to tablehead}%
      \else
        \let\ST@next\@table@last@head
        \ST@trace\tw@{Set heading to tablelasthead}%
      \fi
    \fi
  \else
    \let\ST@next\@tablehead
    \ST@trace\tw@{Set heading to tablehead}%
  \fi
}

\endinput
%%
%% End of file `xtab.sty'.
