summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/supertabular/supertabular.dtx
blob: be31a2d113da9ef17a6e895d1bde640da44aee83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
% \iffalse meta-comment
%
% Copyright 1989-2020 Johannes L. Braams.  All rights reserved.
%
% This file is part of the supertabular package.
% ---------------------------------------------
%
% It may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work is Johannes Braams.
%
% The list of all files belonging to the supertabular package is
% given in the file `MANIFEST.
%
% The list of derived (unpacked) files belonging to the distribution
% and covered by LPPL is defined by the unpacking scripts (with
% extension .ins) which are part of the distribution.
% \fi
%
% \CheckSum{1132}
% \iffalse
%% Sourcefile `supertabular.dtx'.
%%
%% Copyright (C) 1988 by Theo Jurriens 
%% Copyright (C) 1990-2020 by Johannes Braams texniek at braams.xs4all.nl
%%                            Kersengaarde 33
%%                            2723 BP Zoetermeer NL
%%                       all rights reserved.
%%
%%
%<*dtx>
\ProvidesFile{supertabular.dtx}
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{supertabular}
%<driver>\ProvidesFile{supertabular.drv}
%\ProvidesFile{supertabular.dtx}
              [2020/02/02 v4.1g the supertabular environment]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[debugshow]{supertabular}
\newcommand{\tbsp}{\rule{0pt}{18pt}}
\begin{document}
\providecommand{\Lenv}[1]{\textsf{#1}}
\providecommand{\pkg}[1]{\texttt{#1}}
\providecommand{\cls}[1]{\texttt{#1}}
\providecommand{\file}[1]{\texttt{#1}}
\DocInput{supertabular.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{v4.0a}{1996/11/28}{Cleanup of the code, now a \file{.dtx}
%    source file} 
% \changes{v4.0c}{1997/02/20}{Replace \cs{tableformat} by
%    \cs{ST@tableformat} to prevent a clash with the \pkg{KOMA}
%    pacakage} 
% \changes{v4.0f}{1997/04/10}{Repaired a few typos in the
%    documentation}
% \changes{v4.1a}{1997/09/18}{Repaired a number of typos and added
%    contributed mpsupertabular environemnts} 
% \changes{v4.1b}{1997/10/08}{Renamed \cs{@@tabularcr} to
%    \cs{org@tabularcr}}
%
%  \GetFileInfo{supertabular.dtx}
%  \title{The \texttt{supertabular} environment\thanks{This file
%        has version number \fileversion, last
%        revised \filedate.}}
%  \author{Johannes Braams and Theo Jurriens}
%  \date{\filedate}
%  \maketitle
%
%  \section{Introduction}
%
%    The package \pkg{supertabular} offers a new environment, the
%    \Lenv{supertabular} environment. As the name indicates it is an
%    extension of the normal \Lenv{tabular} environment.
%
%    With the original \Lenv{tabular} environment a tabular must
%    always fit on \emph{one} page. If the tabular becomes too large
%    the text overwrites the page's bottom margin and you get an
%    \texttt{Overfull vbox} message. 
%
%    The \Lenv{supertabular} environment uses the \Lenv{tabular}
%    environment internally, but it evaluates the used space every
%    time it gets a |\\| command. If the tabular reaches the
%    textheight, it automatically inserts an optional tabletail, an
%    |\end{tabular}| command, starts a new page, a new
%    \Lenv{tabular} environment and inserts the optional tablehead on
%    the new page continuing the tabular.  
%
%  \section{User interface}
%
%    The package \pkg{supertabular} has three options, they control
%    the amount of information that is written to the \file{.log}
%    file. 
%    \begin{enumerate}
%    \item The option \textsf{errorshow} (the default) doens't write
%      any extra information. 
%    \item The option \textsf{pageshow} writes information about when
%      and why \pkg{supertabular} decides to break the tabular
%      environment in order to produce a new page. 
%    \item The option \textsf{debugshow} also adds information about
%      each line that is added to the tabular.
%    \end{enumerate}
%
%    Below is a description of the new commands and environments that
%    this package provides.
%
%  \DescribeMacro{\tablefirsthead}
%    The command |\tablefirsthead| takes one argument, it defines the
%    contents of the first occurence of the tabular head.\\ 
%    The use of this command is optional. Don't forget to close the
%    head by a |\\|.
%
%  \DescribeMacro{\tablehead}
%    The command |\tablehead| takes one argument, it defines the
%    contents of all subsequent ocurrences of the tabular head.\\ 
%    Don't forget to close the head by a |\\|
%
%  \DescribeMacro{\tabletail}
%    The command |\tabletail| takes one argument, it defines something
%    which should be inserted before each |\end{tabular}|, except
%    the last. 
%
%  \DescribeMacro{\tablelasttail}
%    The command |\tablelasttail| takes one argument, it defines
%    something which should be inserted before the last
%    |\end{tabular}|.\\
%    The use of this command is optional.
%
%  \DescribeMacro{\topcaption}
%  \DescribeMacro{\bottomcaption}
%  \DescribeMacro{\tablecaption}
%    These commands all take the same arguments as \LaTeX's standard
%    |\caption| command. They provide a caption for the super-table,
%    either at the top or at the bottom of the table. When
%    |\tablecaption| is used the caption will be placed at the
%    default location, which is at the top.
%
%  \DescribeEnv{supertabular}
%  \DescribeEnv{supertabular*}
%    The environments \Lenv{supertabular} and \Lenv{supertabular*}
%    can be used much like the standard \LaTeX\ environments
%    \Lenv{tabular} and \Lenv{tabular*}.
%
%  \DescribeEnv{mpsupertabular}
%  \DescribeEnv{mpsupertabular*}
%     The environments \Lenv{mpsupertabular} and
%    \Lenv{mpsupertabular*} work like the \Lenv{supertabular} and
%    \Lenv{supertabular*} environments but put each page into a
%    \Lenv{minipage} first. Thus it is possible to have footnotes
%    inside a \Lenv{mpsupertabular}. The footnotetext is printed at
%    the end of each page. 
% 
%  \DescribeMacro{\shrinkheight}
%    The allowed maximimum height of a part of the supertabular on a
%    page can be adjusted using the command |\shrinkheight|. It takes
%    one argument, the length with which to shrink (positive value) or
%    grow (negative value) the allowed height.
%
%  \section{Weak points}
%
%  \begin{itemize}
%  \item When the material of a normal entry (not a p-arg) becomes
%    larger than the estimated |\ST@lineht|, overfull |\vbox|es
%    will be produced at all. 
%  \item 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. 
%  \item 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 the allowed height
%    of the table with the command |\shrinkheight{...pt}| after the
%    first |\\| of the supertabular. 
%  \item The \Lenv{mpsupertabular} environment sometimes has problems 
%    with pagebreaks when footnotes appear in the lower part of the 
%    tabular. 
%  \end{itemize}
%
%  \section{Examples}
%
%  \DeleteShortVerb{\|}
%    Here is an example of a \Lenv{supertabular}. 
%    First,  here is (part of) the user input for the table below:
%\begin{verbatim}
%    \begin{center}
%    \tablefirsthead{%
%      \hline
%      \multicolumn{1}{|c}{\tbsp Number} &
%      \multicolumn{1}{c}{Number$^2$} &
%      Number$^4$ &
%      \multicolumn{1}{c|}{Number!} \\
%      \hline}
%    \tablehead{%
%      \hline
%      \multicolumn{4}{|l|}{\small\sl continued from previous page}\\
%      \hline
%      \multicolumn{1}{|c}{\tbsp Number} &
%      \multicolumn{1}{c}{Number$^2$} &
%      Number$^4$ &
%      \multicolumn{1}{c|}{Number!} \\
%      \hline}
%    \tabletail{%
%      \hline
%      \multicolumn{4}{|r|}{\small\sl continued on next page}\\
%      \hline}
%    \tablelasttail{\hline}
%    \bottomcaption{This table is split across pages}
%
%    \begin{supertabular}{|r@{\hspace{6.5mm}}|r@{\hspace{5.5mm}}|r|r|}
%    1   &     1  &        1  &           1    \\
%    2   &     4  &       16  &           2    \\
%    3   &     9  &       81  &           6    \\
%    4   &    16  &      256  &          24    \\[5mm]
%    ...
%    19  &   361  &   130321  &  1.21645100E+17\\
%    20  &   400  &   160000  &  2.43290200E+18\\
%    \end{supertabular}
%    \end{center}
%\end{verbatim}
%
%    Then the table should be split across the page boundary:    
%    \begin{center}
%    \tablefirsthead{%
%      \hline
%      \multicolumn{1}{|c}{\tbsp Number} &
%      \multicolumn{1}{c}{Number$^2$} &
%      Number$^4$ &
%      \multicolumn{1}{c|}{Number!} \\
%      \hline}
%    \tablehead{%
%      \hline
%      \multicolumn{4}{|l|}{\small\sl continued from previous page}\\
%      \hline
%      \multicolumn{1}{|c}{\tbsp Number} &
%      \multicolumn{1}{c}{Number$^2$} &
%      Number$^4$ &
%      \multicolumn{1}{c|}{Number!} \\
%      \hline}
%    \tabletail{%
%      \hline
%      \multicolumn{4}{|r|}{\small\sl continued on next page}\\
%      \hline}
%    \tablelasttail{\hline}
%    \bottomcaption{This table is split across pages}
%
%    \begin{supertabular}{|r@{\hspace{6.5mm}}|r@{\hspace{5.5mm}}|r|r|}
%    1\tbsp &  1  &        1  &           1    \\
%    2   &     4  &       16  &           2    \\
%    3   &     9  &       81  &           6    \\
%    4   &    16  &      256  &          24    \\[5mm]
%    5   &    25  &      625  &         120    \\
%    6   &    36  &     1296  &         720    \\
%    7   &    49  &     2401  &        5040    \\
%    8   &    64  &     4096  &       40320    \\
%    9   &    81  &     6561  &      362880    \\
%    10  &   100  &    10000  &     3628800    \\
%    11  &   121  &    14641  &    39916800    \\
%    12  &   144  &    20736  &   479001600    \\[.5cm]
%    \hline & & & \\
%    13  &   169  &    28561  &  6.22702080E+9 \\[1cm]
%    14  &   196  &    38416  &  8.71782912E+10\\
%    15  &   225  &    50625  &  1.30767437E+12\\
%    16  &   256  &    65536  &  2.09227899E+13\\
%    17  &   289  &    83521  &  3.55687428E+14\\[5mm]
%    18  &   324  &   104976  &  6.40237370E+15\\
%    19  &   361  &   130321  &  1.21645100E+17\\
%    20  &   400  &   160000  &  2.43290200E+18\\
%    \end{supertabular}
%    \end{center}
%
%    Here is another example whith a \texttt{p} column-definition. The
%    tablehead is the same as above. The tabletail is a double
%    \verb|\hline|; \verb|\arraystretch| is set to \texttt{1.5} and
%    the font size is \verb|\small|. 
%
%    \begin{center}
%    \tablefirsthead{%
%      \hline
%      \multicolumn{1}{|c}{\tbsp Number} &
%      \multicolumn{1}{c}{Number$^2$} &
%      Number$^4$ &
%      \multicolumn{1}{c|}{Number!} \\
%      \hline}
%    \tablelasttail{\hline\hline}
%    \topcaption{This table should also be split accross pages.}
%    \renewcommand{\arraystretch}{1.5}
%    \small
%    \begin{supertabular}{| r@{\hspace{6.5mm}}|%
%                           r@{\hspace{5.5mm}}| r p{5cm}|}
%    1  &  1  &  1  &  \tbsp here is a relative short entry \\
%    2  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    3  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    4  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    5  &  1  &  1  &  here is a relative short entry \\
%    6  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    7  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    8  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    9  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    10 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    11 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    12 &  1  &  1  &  here is a relative short entry \\
%    13 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    14 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    15 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    16 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    17 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    18 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    \end{supertabular}
%    \end{center}
%
%    Here is the same table again, but this time using the
%    \Lenv{supertabular*} environment and stretching the table to the
%    full width of the text. 
%
%    \begin{center}
%    \tablefirsthead{%
%      \hline
%      \multicolumn{1}{|c}{\tbsp Number} &
%      \multicolumn{1}{c}{Number$^2$} &
%      Number$^4$ &
%      \multicolumn{1}{c|}{Number!} \\
%      \hline}
%    \tablelasttail{\hline\hline}
%    \topcaption{This table should also be split accross pages.}
%    \renewcommand{\arraystretch}{1.5}
%    \small
%    \begin{supertabular*}{\textwidth}%
%                         {| r@{\extracolsep{6.5mm plus 1fil}}|%
%                            r@{\extracolsep{5.5mm plus 0.5fil}}|%
%                            r@{\extracolsep{0mm plus 0.1fil}}%
%                            p{5cm}|}
%    1  &  1  &  1  &  \tbsp here is a relative short entry \\
%    2  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    3  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    4  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    5  &  1  &  1  &  here is a relative short entry \\
%    6  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    7  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    8  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    9  &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    10 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    11 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    12 &  1  &  1  &  here is a relative short entry \\
%    13 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    14 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    15 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    16 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    17 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    18 &  1  &  1  &  and here is a long entry, where line breaks
%                      and line breaks and line breaks have to occur\\
%    \end{supertabular*}
%    \end{center}
%
%  \MakeShortVerb{\|}
%
%  \section{Known problems}
%
%    \begin{itemize}
%    \item When a float occurs on the same page as the start of a
%      supertabular you can expect unexpected results. 
%
%      When the float was defined on the same page you might end up
%      with the first part of the supertabular on a page by its own. 
%
%    \item You should not use the supertabular \emph{inside} a
%      floating-environment such as \texttt{table} as this will result
%      in \TeX\ trying to put the whole supertabular on \emph{one}
%      page. 
%
%    \item In some instances you might still end up with overfull
%      |\vbox| messages. 
%
%    \item Sometimes the last page of the supertabular contains just
%       an empty head an tail. 
%    \end{itemize}
%  \StopEventually{}
%
%  \section{The Implementation}
%    First we define a few options that control the level of tracing
%    output this package delivers. the option \textsf{errorshow} is the
%    default situation.
% \changes{v4.1f}{2019/01/16}{The value for \cs{C@tracingst} needs to
%    be 3 instead of 2} 
%    \begin{macrocode}
%<*package>
\newcount\c@tracingst
\DeclareOption{errorshow}{\c@tracingst\z@}
\DeclareOption{pageshow}{\c@tracingst\thr@@}
\DeclareOption{debugshow}{\c@tracingst5\relax}
\ProcessOptions
%    \end{macrocode}
%
% \begin{macro}{\topcaption}
% \begin{macro}{\bottomcaption}
%    The user-commands |\topcaption| and |\bottomcaption| set the
%    flag |@topcaption| to determine where to put the
%    tablecaption. The default is to put the caption on the top of
%    the table 
%    \begin{macrocode}
\newif\if@topcaption \@topcaptiontrue
\def\topcaption{\@topcaptiontrue\tablecaption}
\def\bottomcaption{\@topcaptionfalse\tablecaption}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\tablecaption}
%    This command has to function exactly like |\caption| does, except
%    it has to store its argument (and the optional argument) for
%    later processing \emph{within} the supertabular environment. 
%
%    \begin{macrocode}
\long\def\tablecaption{%
  \refstepcounter{table}\@dblarg{\@xtablecaption}}
\long\def\@xtablecaption[#1]#2{%
  \long\gdef\@process@tablecaption{\ST@caption{table}[#1]{#2}}}
\global\let\@process@tablecaption\relax
%    \end{macrocode}
% \end{macro}
%
%  \begin{macro}{\ifST@star}
%    This switch is used in the internal macros to remember which
%    kind of environment was started.
%    \begin{macrocode}
\newif\ifST@star
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ifST@mp}
%    This switch is used in the internal macros to remember if the
%    tabular should be put into a minipage.
% \changes{v4.1a}{1997/09/18}{Added \cs{ifST@mp} switch}
%    \begin{macrocode}
\newif\ifST@mp
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@wd}
%    For the \Lenv{supertabular*} environment it is necessary to
%    store the intended width of the tabular.
%    \begin{macrocode}
\newdimen\ST@wd
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@rightskip}
% \changes{v4.1a}{1997/09/18}{Dimen register added}
%  \begin{macro}{\ST@leftskip}
% \changes{v4.1a}{1997/09/18}{Dimen register added}
%  \begin{macro}{\ST@parfillskip}
% \changes{v4.1a}{1997/09/18}{Dimen register added}
%    For the \Lenv{mpsupertabular} environments we need special
%    versions of |\leftskip|, |\rightskip| and |\parfillskip|.
%    \begin{macrocode}
\newskip\ST@rightskip
\newskip\ST@leftskip 
\newskip\ST@parfillskip
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\ST@captionroom}
% \changes{v4.1g}{2020/02/02}{New macro}
%    When a supertabular is preceded by a caption that fact might not
%    yet be visible in the amount of space occupoed on the page
%    sofar. Therefore we include the possibility to reduce the height
%    of the first part of the supertabular. In order to this we need a
%    macro that indicates a aption has been put in front of the
%    table. We do this to reduce the risk that the first part of the
%    table is too high after all and is pushed onto the next page due
%    to an overfull |\vbox| condition.
%    \begin{macrocode}
\def\ST@captionroom{\z@}
%    \end{macrocode}
%  \end{macro}
%
%  
%  \begin{macro}{\ST@caption}
%    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 the document class \cls{article} and friends
%    that a caption \textbf{always} gets a |\vskip 10pt| at the top
%    and \textbf{none} at the bottom. If a user wants to precede his
%    table with a caption this results in a collision. 
%
% \changes{v4.1g}{2020/02/02}{Record the fact that a caption has
%    preceeded the table by setting \cs{ST@captionroom}}
%    \begin{macrocode}
\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@ \gdef\ST@captionroom{20\p@}\fi
  \endgroup}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\tablehead}
% \changes{v4.0a}{1996/11/28}{Locally reset \cs{}\cs{} to \cs{cr}}
%  \begin{macro}{\tablefirsthead}
%    |\tablehead| activates the new tabular |\cr| commands.
% \changes{v4.0i}{1997/09/18}{Don't reset \cs{}\cs{} to \cs{cr}, but
%    to \cs{@tabularcr}} 
% \changes{v4.1b}{1997/10/08}{Not \cs{@tabularcr} but
%    \cs{org@tabularcr}}
%    \begin{macrocode}
\newcommand\tablehead[1]{%
  \gdef\@tablehead{%
  \noalign{%
      \global\let\@savcr=\\
      \global\let\\=\org@tabularcr}%
    #1%
    \noalign{\global\let\\=\@savcr}}}
\tablehead{}
%    \end{macrocode}
%    It's possible to specify a different tablehead for the first
%    `part' of the table. That only needs to be used once so it
%    `undefines' itself at the end. That way we make sure that it
%    doesn't accidentally get used for a second supertabular in the
%    document.
% \changes{v4.1f}{2019/01/12}{\cs{\@table@first@head} needs the same
%    definition as \cs{\@tablehead} (found by FMi)}
%    \begin{macrocode}
\newcommand\tablefirsthead[1]{%
  \gdef\@table@first@head{%
    \noalign{%
      \global\let\@savcr=\\
      \global\let\\=\org@tabularcr}%
    #1%
    \noalign{%
      \global\let\\=\@savcr
      \global\let\@table@first@head\undefined
    }}}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\tabletail}
%  \begin{macro}{\tablelasttail}
%    If the user uses an extra amount of tabular-data (like
%    |\multicolumn|) in |\tabletail| \TeX\ starts looping because of
%    the definition of |\ST@cr|. So make |\\| act just like a
%    |\@tabularcr| inside this tail to prevent the loop.  Save and
%    restore the value of |\\|.
%
% \changes{v4.0i}{1997/09/18}{Don't reset \cs{}\cs{} to \cs{cr}, but
%    to \cs{@tabularcr}} 
% \changes{v4.1b}{1997/10/08}{Not \cs{@tabularcr} but
%    \cs{org@tabularcr}}
%    \begin{macrocode}
\newcommand\tabletail[1]{%
  \gdef\@tabletail{%
    \noalign{%
      \global\let\@savcr=\\
      \global\let\\=\org@tabularcr}%
    #1%
    \noalign{\global\let\\=\@savcr}}}
\tabletail{}
%    \end{macrocode}
%    It's possible to specify a different tabletail for the last
%    `part' of the table. That only needs to be used once so it
%    `undefines' itself at the end. That way we make sure that it
%    doesn't accidentally get used for a second supertabular in the
%    document.
% \changes{v4.1f}{2019/01/12}{\cs{\@table@last@tail} needs the same
%    definition as \cs{\@tabletail}}
%    \begin{macrocode}
\newcommand\tablelasttail[1]{%
  \gdef\@table@last@tail{%
    \noalign{%
      \global\let\@savcr=\\
      \global\let\\=\org@tabularcr}%
    #1%
    \noalign{%
      \global\let\\=\@savcr
      \global\let\@table@last@tail\undefined
    }}}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\sttraceon}
% \changes{v3.7b}{1994/05/16}{Added macro}
%  \begin{macro}{\sttraceoff}
% \changes{v3.7b}{1994/05/16}{Added macro}
%    There now is a possiblity to follow the decisions supertabular
%    makes about breaking the tabular. This has to be enabled when
%    converting this file with \texttt{docstrip} to a \texttt{.sty}
%    file. 
%    \begin{macrocode}
\newcommand\sttraceon{\c@tracingst5\relax}
\newcommand\sttraceoff{\c@tracingst\z@}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\ST@trace}
%    A macro that gets the trace message as its argument
%    \begin{macrocode}
\newcommand\ST@trace[2]{%
  \ifnum\c@tracingst>#1\relax
    \GenericWarning
      {(supertabular)\@spaces\@spaces}
      {Package supertabular: #2}%
  \fi
  }
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@trace@cr}
%    A variant of |\ST@trace| that can be called from within |\\| as
%    that command is looking for an optional argument will end up
%    scanning the next line.
%  \begin{macro}{\ST@save@lineno}
% \changes{v4.1f}{2019/01/18}{Added a macro to save the current input
%    linenumber}
%    But because this variant is called from within |\\| we need to
%    save the current input linenumber before \TeX\ starts scanning
%    for the optional argument. If we don't, the reported linenumber
%    depends on whether or not the optional argument is present...
%    \begin{macrocode}
\newcommand\ST@save@lineno{%
  \expandafter\gdef\expandafter\ST@LineNo\expandafter{%
    \the\inputlineno}}
%    \end{macrocode}
%    Within |\ST@trace@cr| we can than locally modify |\on@line| to
%    use this saved line number.
%    \begin{macrocode}
\newcommand\ST@trace@cr[2]{%
  \ifnum\c@tracingst>#1\relax
  \begingroup
  \edef\on@line{ on input line \ST@LineNo}%
    \GenericWarning
      {(supertabular)\@spaces\@spaces}
      {Package supertabular: #2}%
  \endgroup
  \fi
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%  \begin{macro}{\ST@pageleft}
% \changes{v3.7b}{1994/05/16}{Renamed from \cs{maxsize}}
% \changes{v4.0a}{1996/11/28}{Renamed from \cs{page@left}}
%    This register holds the estimate of the amount of space left over
%    on the current page. This is used in the decision when to start a
%    new page.
%    \begin{macrocode}
\newdimen\ST@pageleft
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\shrinkheight}
% \changes{v4.0a}{1996/11/28}{New command}
% \changes{v4.0h}{1997/05/20}{This command should use \cs{advance} but
%    didn't...} 
%    A command to diminish the value of |\ST@pageleft| if necessary.
%    \begin{macrocode}
\newcommand*\shrinkheight[1]{%
  \noalign{\global\advance\ST@pageleft-#1\relax}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\setSTheight}
% \changes{v4.0h}{1997/05/10}{New command}
%    A command to set the value of |\ST@pageleft| if necessary.
%    \begin{macrocode}
\newcommand*\setSTheight[1]{%
  \noalign{\global\ST@pageleft=#1\relax}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@headht}
%  \begin{macro}{\ST@tailht}
%    The register |ST@headht| will hold the height of the first head
%    of a \Lenv{supertabular} environment; the register |\ST@tailht|
%    will hold the height of table tail (if any)
%    \begin{macrocode}
\newdimen\ST@headht
\newdimen\ST@tailht
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\ST@pagesofar}
%    The register |\ST@pagesofar| is used to store the estimate of the
%    amount of page already filled up.
%    \begin{macrocode}
\newdimen\ST@pagesofar
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@pboxht}
%    The measured (total) height  of a parbox-argument
%    \begin{macrocode}
\newdimen\ST@pboxht
%    \end{macrocode}
%  \end{macro}
%
% \changes{v4.0b}{1997/02/04}{Removed the use of \cs{ST@pboxcorr},
%    correction seems to be no longer necessary}
%
%  \begin{macro}{\ST@lineht}
%  \begin{macro}{\ST@stretchht}
% \changes{v4.0g}{1997/04/12}{Dimension register added}
%  \begin{macro}{\ST@prevht}
% \changes{v4.0g}{1997/04/12}{Dimension register added}
%    The estimated height of a normal line is stored in
%    |\ST@lineht|. The dimension register |\ST@stretchht| is used to
%    store the difference between the `normal' line height and the
%    line height when |\arraystretch| has a non-standard value. This
%    is used in the case where p-box entries are added to the
%    tabular. The dimension register |\ST@prevht| is use to store the
%    height of the previous line to use it as an estimate for the
%    height of the next line. This is needed for a better estimate of
%    when to break the tabular. 
% \changes{v4.1g}{2020/02/02}{\cs{ST@stretchht} is no longer needed,
%    will be removed in a future release}
%    \begin{macrocode}
\newdimen\ST@lineht
%\newdimen\ST@stretchht
\newdimen\ST@prevht
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\ST@toadd}
%    When a tabular row is ended with |\\[...]| we need to temporarily
%    store the optional argument in |\ST@toadd|.
%    \begin{macrocode}
\newdimen\ST@toadd
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@dimen}
%    A private scratch dimension register.
%    \begin{macrocode}
\newdimen\ST@dimen
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@pbox}
%    A box register to temporarily store the contents of a parbox.
%    \begin{macrocode}
\newbox\ST@pbox
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@tabularcr}
%  \begin{macro}{\ST@xtabularcr}
%  \begin{macro}{\ST@argtabularcr}
%    These are redefinitions of |\@tabularcr| and |\@xtabularcr|. This
%    is needed to include |\ST@cr| in the definition of
%    |\@xtabularcr|. 
%
%    All redefined macros have names that are similar to the original
%    names, except with a leading 'ST'.
%    \begin{macrocode}
% \changes{v4.1f}{2019/01/18}{Save the input linenumber before \TeX\
%    scans for an optional argument}
\def\ST@tabularcr{%
  {\ifnum0=`}\fi
  \ST@save@lineno
  \@ifstar{\ST@xtabularcr}{\ST@xtabularcr}}
\def\ST@xtabularcr{%
  \@ifnextchar[%]
    {\ST@argtabularcr}%
    {\ifnum0=`{\fi}\cr\ST@cr}}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%    \begin{macrocode}
\def\ST@argtabularcr[#1]{%
  \ifnum0=`{\fi}%
  \ifdim #1>\z@
    \unskip\ST@xargarraycr{#1}
  \else 
    \ST@yargarraycr{#1}%
  \fi}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@xargarraycr}
%  \begin{macro}{\ST@yargarraycr}
%    In this case we need to copy the value of the optional argument
%    of |\\| in our private register |\ST@toadd|.
%    \begin{macrocode}
\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}
%    \end{macrocode}
%  \end{macro}
%
%    Here we need to insert |\ST@cr|
%    \begin{macrocode}
\def\ST@yargarraycr#1{%
  \cr\noalign{\vskip #1\global\ST@toadd=#1}\ST@cr}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@startpbox}
%    The macros that deal with parbox columns need to be redefined,
%    because we need to know the size of the parbox.
% \changes{v4.0b}{1997/02/04}{Removed use of \cs{ST@pboxcorr}}
%    \begin{macrocode}
\def\ST@startpbox#1{%
%    \end{macrocode}
%    To achieve our goal we need to save the text in box.
%    \begin{macrocode}
  \setbox\ST@pbox\vtop\bgroup\hsize#1\@arrayparboxrestore}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@astartpbox}
%    Our version of |\@astartpbox|.
% \changes{v4.0b}{1997/02/04}{Removed use of \cs{ST@pboxcorr}}
%    \begin{macrocode}
\def\ST@astartpbox#1{%
  \bgroup\hsize#1%
  \setbox\ST@pbox\vtop\bgroup\hsize#1\@arrayparboxrestore}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\ST@endpbox}
%  \begin{macro}{\ST@aendpbox}
% \changes{v4.0a}{1996/11/30}{Made definitions up to date with
%    \file{latex.ltx} (1996/06/01)} 
%    Our version of |\@endpbox| and |\@aendpbox|.
%    \begin{macrocode}
\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}
%    \end{macrocode}
%    
%    \begin{macrocode}
\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}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
% 
% \begin{macro}{\ST@compute@lineht}
% \changes{v4.1g}{2020/02/02}{New macro \cs{ST@compute@lineht} to
%    replacte \cs{estimate@lineht}} 
%    The height of a line in an array environemnt can be computed as:
%    \begin{itemize}
%      \item the height of the strutbox |\ht\strutbox| (plus
%        |\extrarowheight| when the \pkg{array} package is loaded),
%      \item multiplied by arraystretch,
%      \item plus the depth of the strutbox (|\dp\strutbox|) mulitplied
%        by |\arraystretch|.
%    \end{itemize}
%    \begin{macrocode}
\def\ST@compute@lineht{%
  \ST@lineht=\ht\strutbox
  \ifx\extrarowheight\undefined\else
    \advance \ST@lineht by \extrarowheight
  \fi
  \ST@lineht = \arraystretch\ST@lineht
  \advance\ST@lineht \arraystretch\dp\strutbox
  \ST@trace\tw@{Normal Line height: \the\ST@lineht}%
  }
%    \end{macrocode}
% \end{macro}
%    
% \begin{macro}{\estimate@lineht}
%    Estimates the height of normal line taking |\arraystretch| into
%    account. Also computes the difference between a normal line and a
%    `stretched' one.
% \changes{v4.0b}{1997/02/04}{Removed use of \cs{ST@pboxcorr}}
% \changes{v4.0g}{1997/04/12}{Added the computation of
%    \cs{ST@stretchht}}
%    This macro will be removed in a future release.
% \begin{macrocode}
\def\estimate@lineht{%
  \ST@lineht=\arraystretch \baslineskp
  \global\advance\ST@lineht by 1\p@
  \ST@stretchht\ST@lineht\advance\ST@stretchht-\baslineskp
  \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}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@calfirstpageht}
% \changes{v3.7a}{1993/04/05}{Renamed from \cmd\calpage}
%    Estimates the space left on the current page and decides whether
%    the tabular can be started on this page or on a new page.
%    \begin{macrocode}
\def\@calfirstpageht{%
  \ST@trace\tw@{Calculating height of tabular on first page}%
%    \end{macrocode}
%    The \TeX\ register |\pagetotal| contains the height of the page
%    sofar, the \LaTeX\ register |\@colroom| contains the height of
%    the column.
%    \begin{macrocode}
  \global\ST@pagesofar\pagetotal
  \global\ST@pageleft\@colroom
  \ST@trace\tw@{Height of text = \the\pagetotal; \MessageBreak
                Height of page = \the\ST@pageleft}%
%    \end{macrocode}
%    When we are in twocolumn mode \TeX\ may still be collecting
%    material for the first column although there seems to be no space
%    left. In this case we have to check against two times |\ST@pageleft|.
%    \begin{macrocode}
  \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
%    \end{macrocode}
%    In this case we're in the second column, so we have to compensate
%    for the material in the first column.
%    \begin{macrocode}
          \ST@trace\tw@{Second column}%
          \global\advance\ST@pageleft -\ST@pagesofar
          \global\advance\ST@pageleft -\@colroom
        \fi
%    \end{macrocode}
%    When |\ST@pagesofar| is smaller than |\ST@pageleft| \TeX\ is
%    still collecting material for the first column, so we can start a
%    new tabular environment like we do on a single column page.
% \changes{v4.0i}{1997/09/17}{Added initialisation for the case where
%    the first column isn't full yet} 
%    \begin{macrocode}
      \else
        \global\advance\ST@pageleft by -\ST@pagesofar
        \global\ST@pagesofar\z@
      \fi
    \else
%    \end{macrocode}
%    When we end up here, \TeX\ has already decided it had enough
%    material for the first column and is building the second column.
% \changes{v4.1a}{1997/09/27}{Added initialisation for 2nd column of
%    twocolumn mode} 
%    \begin{macrocode}
      \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
%    \end{macrocode}
%    In one column mode there is a simple decision.
%    \begin{macrocode}
    \ST@trace\tw@{one column mode}%
    \ifnum\ST@pagesofar > \ST@pageleft
      \ST@trace\tw@{starting new page}%
      \newpage\@calnextpageht
%    \end{macrocode}
%    When we are not starting a new page subtract the size of the
%    material already on it from the available space.
%    \begin{macrocode}
    \else
      \global\advance\ST@pageleft by -\ST@pagesofar
      \global\ST@pagesofar\z@
    \fi
  \fi
%    \end{macrocode}
%    When a caption preceeds the first part of the tabular we need to
%    reduce the available height on the page by |\ST@captionroom|.
% \changes{v4.1g}{2020/02/02}{Reduce the available height left on the
%    page when a caption preceeded the table} 
%    \begin{macrocode}
  \if@topcaption\advance\ST@pageleft-\ST@captionroom\fi
  \ST@trace\tw@{Available height: \the\ST@pageleft}%
%    \end{macrocode}
%    Now we need to know the height of the head of the table. In order
%    to measure this we typeset it in a normal \Lenv{tabular}
%    environment.
%    \begin{macrocode}
  \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}%
%    \end{macrocode}
%    To decide when to start a new page, we need to know the vertical
%    size of the tail of the table.
%    \begin{macrocode}
  \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
%    \end{macrocode}
%    We add the average height of a line to this because when we
%    decide to continue the tabular we need to have enough space left
%    for one line and the tail.
%    \begin{macrocode}
  \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
%    \end{macrocode}
% \changes{v4.0b}{1997/02/04}{Base the decision whether to start on a
%    new page on the total of headheight, tailht and lineht}
%    Now we decide whether we can continue on the current page or
%    whether we need to start on a new page. We assume that the
%    minimum height of a tabular is the height of the head, the tail
%    and one line of data. If that doesn't fit a new page is started.
%    \begin{macrocode}
  \advance\@tempdima\ST@lineht
  \advance\@tempdima\ST@tailht
  \ST@trace\tw@{Minimum height of tabular: \the\@tempdima}%
  \ifnum\@tempdima>\ST@pageleft
    \ST@trace\tw@{starting new page}%
    \newpage\@calnextpageht
  \fi
%    \end{macrocode}
%    Take the height of the table into account,sosubstract it from the
%    available height. We need to do it like this because the |\\|
%    inside the definition of |\@@tablehead| have their normal
%    definition.
% \changes{v4.1g}{2020/02/02}{Subtract the height of the tablehead
%    from the available space}
%    \begin{macrocode}
  \advance\ST@pageleft-\ST@headht
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@calnextpageht}
% \changes{v3.7a}{1993/04/05}{Macro added}
% \changes{v4.0b}{1997/02/04}{Removed use of \cs{ST@pboxcorr}}
%    This calculates the maximum height of the tabular on all
%    subsequent pages of the supertabular environment.
%    \begin{macrocode}
\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}%
%    \end{macrocode}
%    Take the height of the head into account by subtracting it from
%    the avalable space.
% \changes{v4.1g}{2020/02/02}{Subtract \cs{ST@headht} from
%    \cs{ST@pageleft}} 
%    \begin{macrocode}
  \advance\ST@pageleft-\ST@headht
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\x@supertabular}
%    The body of the beginning of both environments is stored in a
%    single macro as the code is shared.
%    \begin{macrocode}
\def\x@supertabular{%
%    \end{macrocode}
%    First save the original definition of |\tabular| and then make it
%    point to |\inner@tabular|. This is done to enable supertabular
%    cells to contain a \Lenv{tabular} environment without getting
%    unexpected results when the \Lenv{supertabular} would be split
%    accross this inner \Lenv{tabular} environment.
% \changes{v4.0d}{1997/03/06}{Save definition of \cs{tabular} and
%    \cs{tabular*}} 
%    \begin{macrocode}
  \let\org@tabular\tabular
  \let\tabular\inner@tabular
%    \end{macrocode}
%    The same needs to be done for the \Lenv{tabular*}
%    environment. The coding is slightly more verbose.
%    \begin{macrocode}
  \expandafter\let
    \csname org@tabular*\expandafter\endcsname
    \csname tabular*\endcsname
  \expandafter\let\csname tabular*\expandafter\endcsname
    \csname inner@tabular*\endcsname
%    \end{macrocode}
%    If the caption should come at the top we insert it here.
%    \begin{macrocode}
  \if@topcaption \@process@tablecaption \fi
%    \end{macrocode}
%    Save the original definition of |\\|.
%    \begin{macrocode}
  \global\let\@oldcr=\\
%    \end{macrocode}
%    Save the current value of |\baselineskip|, as we need it in the
%    calculation of the average height of a line. 
%    \begin{macrocode}
  \def\baslineskp{\baselineskip}%
%    \end{macrocode}
%    We have to check whether \texttt{array.sty} was loaded, because
%    some of the internal macros have different names.
%    \begin{macrocode}
  \ifx\undefined\@classix
%    \end{macrocode}
%    Save old |\@tabularcr| and insert the definition of
% \changes{v4.1c}{1997/11/07}{For standard \LaTeX\ we need to change
%    \cs{@@startpbox}, \emph{not} \cs{@startpbox}}
%    |\ST@tabularcr|. 
%    \begin{macrocode}
    \let\org@tabularcr\@tabularcr
    \let\@tabularcr\ST@tabularcr
%    \end{macrocode}
%    Activate the new parbox algorithm.
%    \begin{macrocode}
    \let\org@startpbox=\@startpbox
    \let\org@endpbox=\@endpbox
    \let\@@startpbox=\ST@startpbox
    \let\@@endpbox=\ST@endpbox
  \else
%    \end{macrocode}
%    When \texttt{array.sty} was loaded things are a bit different.
%    \begin{macrocode}
    \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
%    \end{macrocode}
%
%    Check if the head of the table should be different for the first
%    and subsequent pages.
%    \begin{macrocode}
  \ifx\@table@first@head\undefined
    \let\@@tablehead=\@tablehead
  \else
    \let\@@tablehead=\@table@first@head
  \fi
%    \end{macrocode}
%    The first part of a supertabular may be moved on to the next page
%    if it doesn't fit on the current page afterall. Subsequent parts
%    can not be moved; therefor we will have to switch the definition
%    of |\ST@skippart| around.
% \changes{v4.0e}{1997/04/09}{Make sure that only the first part of a
%    supertabular can be moved to the next page.} 
%    \begin{macrocode}
  \let\ST@skippage\ST@skipfirstpart
%    \end{macrocode}
%    Now we can estimate the average line height and the height of the
%    first page of the \Lenv{supertabular}.
% \changes{v4.0i}{1997/09/18}{Added \cs{noindent}}
% \changes{v4.1g}{2020/02/02}{Now call \cs{ST@compute@lineht}}
%    \begin{macrocode}
  \ST@compute@lineht
  \@calfirstpageht
  \noindent
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\supertabular}
%    We start by looking for an optional argument, which will be duly
%    ignored as it seems to make no sense to try to align a multipage
%    table in the middle...
%    \begin{macrocode}
\def\supertabular{%
  \@ifnextchar[{\@supertabular}%]
               {\@supertabular[]}}
%    \end{macrocode}
%    We can now save the preamble of the tabular in a macro.
%    \begin{macrocode}
\def\@supertabular[#1]#2{%
  \def\ST@tableformat{#2}%
  \ST@trace\tw@{Starting a new supertabular}%
%    \end{macrocode}
%    Then remember that this is not a \textsf{supertabular*}
%    environment.
%    \begin{macrocode}
  \global\ST@starfalse
%    \end{macrocode}
%    Don't use minipages.
% \changes{v4.1a}{1997/09/18}{Added setting of \cs{ST@mp}}
%    \begin{macrocode}
  \global\ST@mpfalse
%    \end{macrocode}
% 
%    Most of the following code is shared between the
%    \Lenv{supertabular} and \Lenv{supertabular*} environments. So to
%    avoid duplication it is stored in a macro.  
%    \begin{macrocode}
  \x@supertabular
%    \end{macrocode}
%    Finally start a normal \textsf{tabular} environment.
% \changes{v4.0d}{1997/03/06}{Use \cs{org@tabular} instead of
%    \cs{tabular}} 
%    \begin{macrocode}
  \expandafter\org@tabular\expandafter{\ST@tableformat}%
  \@@tablehead}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\supertabular*}
%    We start by looking for the optional argument of the tabular
%    environment. 
%    \begin{macrocode}
\@namedef{supertabular*}#1{%
  \@ifnextchar[{\@nameuse{@supertabular*}{#1}}%
               {\@nameuse{@supertabular*}{#1}[]}%]
  }
%    \end{macrocode}
%    We start by saving the intended width and the preamble of the
%    \textsf{tabular*}.
%    \begin{macrocode}
\@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
%    \end{macrocode}
%    Now we can call the common code for both environments.
%    \begin{macrocode}
  \x@supertabular
%    \end{macrocode}
%    And we can start a normal \textsf{tabular*} environment.
% \changes{v4.0f}{1997/04/11}{Use \cs{org@tabular*} instead of
%    \cs{tabular*}}
%    \begin{macrocode}
  \expandafter\csname org@tabular*\expandafter\endcsname
  \expandafter{\expandafter\ST@wd\expandafter}%
  \expandafter{\ST@tableformat}%
  \@@tablehead}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\mpsupertabular}
% \changes{v4.1a}{1997/09/18}{Added \cs{mpsupertabular}}
%
%    This version of the supertabular environment puts each tabular 
%    into a minipage, thus making footnotes possible.
%    We start by looking for an optional argument, which will be duly
%    ignored as it seems to make no sense to try to align a multipage
%    table in the middle\dots
%    \begin{macrocode}
\def\mpsupertabular{%
  \@ifnextchar[{\@mpsupertabular}%]
               {\@mpsupertabular[]}}
%    \end{macrocode}
%    We can now save the preamble of the tabular in a macro.
%    \begin{macrocode}
\def\@mpsupertabular[#1]#2{%
  \def\ST@tableformat{#2}%
  \ST@trace\tw@{Starting a new mpsupertabular}%
%    \end{macrocode}
%    Then remember that this is not a \textsf{mpsupertabular*}
%    environment.
%    \begin{macrocode}
  \global\ST@starfalse
%    \end{macrocode}
%
%    And remember to close the minipage later.
%    \begin{macrocode}
  \global\ST@mptrue
%    \end{macrocode}
%
%    Since we are about to start a minipage of |\columnwidth| the 
%    horizontal alignment will no longer work. We have to remember the 
%    values and restore them inside the minipage.
%    \begin{macrocode}
  \ST@rightskip \rightskip
  \ST@leftskip \leftskip
  \ST@parfillskip \parfillskip
%    \end{macrocode}
%
%    Most of the following code is shared between the
%    \Lenv{mpsupertabular} and \Lenv{mpsupertabular*} environments. So
%    to avoid duplication it is stored in a macro.
%    \begin{macrocode}
  \x@supertabular
%    \end{macrocode}
%    Finally start a normal \textsf{tabular} environment.
% \changes{v4.1a}{1997/09/18}{Open minipage and adjust skips}
%    \begin{macrocode}
  \minipage{\columnwidth}%
  \parfillskip\ST@parfillskip
  \rightskip \ST@rightskip 
  \leftskip \ST@leftskip 
  \noindent\expandafter\org@tabular\expandafter{\ST@tableformat}%
  \@@tablehead}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\mpsupertabular*}
% \changes{v4.1a}{1997/09/18}{Added \cs{mpsupertabular*}}
%
%    We start by looking for the optional argument of the tabular
%    environment. 
%    \begin{macrocode}
\@namedef{mpsupertabular*}#1{%
  \@ifnextchar[{\@nameuse{@mpsupertabular*}{#1}}%
               {\@nameuse{@mpsupertabular*}{#1}[]}%]
  }
%    \end{macrocode}
%    Now we can save the intended width and the preamble of the
%    \textsf{tabular*}.
%    \begin{macrocode}
\@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
%    \end{macrocode}
% 
%    Then we can call the common code for both environments.
%    \begin{macrocode}
  \x@supertabular
%    And we can start a normal \textsf{tabular*} environment.
%    \begin{macrocode}
  \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}%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\endsupertabular}
% \begin{macro}{\endsupertabular*}
%    This closes the environments \Lenv{supertabular} and
%    \Lenv{supertabular*}. 
%    \begin{macrocode}
\def\endsupertabular{%
  \ifx\@table@last@tail\undefined
    \@tabletail
  \else
    \@table@last@tail
  \fi
  \csname endtabular\ifST@star*\fi\endcsname
%    \end{macrocode}
%    Restore the original definition of |\@tabularcr|
%    \begin{macrocode}
  \ST@restore
%    \end{macrocode}
%    Check if we have to insert a caption and restore to default
%    behaviour of putting captions at the top.
%    \begin{macrocode}
  \if@topcaption
  \else
    \@process@tablecaption
    \@topcaptiontrue
  \fi
%    \end{macrocode}
%
%    Restore the meaning of |\\| to the one it had before the start
%    of this environment. Also re-initialize some control-sequences
%
% \changes{v4.0h}{1997/05/20}{Added missing \cs{global} commands}
% \changes{v4.1d}{1999/08/07}{No longer make \cs{@table@first@head}
%    and \cs{@table@last@tail} undefined}
%    \begin{macrocode}
  \global\let\\\@oldcr
  \global\let\@process@tablecaption\relax
  \ST@trace\tw@{Ended a supertabular\ifST@star*\fi}%
  }
%    \end{macrocode}
%
%    The definition of the ending of the \Lenv{supertabular*}
%    environment is simple:
%    \begin{macrocode}
\expandafter\let\csname endsupertabular*\endcsname\endsupertabular
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\endmpsupertabular}
% \begin{macro}{\endmpsupertabular*}
%    This closes the environments \Lenv{mpsupertabular} and
%    \Lenv{mpsupertabular*}.
%    \begin{macrocode}
\def\endmpsupertabular{%
  \ifx\@table@last@tail\undefined
    \@tabletail
  \else
    \@table@last@tail
  \fi
  \csname endtabular\ifST@star*\fi\endcsname
  \endminipage
%    \end{macrocode}
%    Restore the original definition of |\@tabularcr|
%    \begin{macrocode}
  \ST@restore
%    \end{macrocode}
%    Check if we have to insert a caption and restore to default
%    behaviour of putting captions at the top.
%    \begin{macrocode}
  \if@topcaption
  \else
    \@process@tablecaption
    \@topcaptiontrue
  \fi
%    \end{macrocode}
%
%    Restore the meaning of |\\| to the one it had before the start
%    of this environment. Also re-initialize some control-sequences
% \changes{v4.1d}{1999/08/07}{No longer make \cs{@table@first@head}
%    and \cs{@table@last@tail} undefined}
%    \begin{macrocode}
  \global\let\\\@oldcr
  \global\let\@process@tablecaption\relax
  \ST@trace\tw@{Ended a mpsupertabular\ifST@star*\fi}%
  }
%    \end{macrocode}
%
%    The definition of the ending of the \Lenv{supertabular*}
%    environment is simple:
%    \begin{macrocode}
\expandafter\let\csname endmpsupertabular*\endcsname\endmpsupertabular
%    \end{macrocode}
% \end{macro}
% \end{macro}
%  \begin{macro}{\ST@restore}
%    This macro restores the original definitions of the macros that
%    handle parbox entries and the macros that handle the end of the
%    row. 
%    \begin{macrocode}
\def\ST@restore{%
  \ifx\undefined\@classix
    \let\@tabularcr\org@tabularcr
  \else
    \let\@arraycr\org@tabularcr
  \fi
  \let\@startpbox\org@startpbox
  \let\@endpbox\org@endpbox
  }
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\inner@tabular}
%  \begin{macro}{\inner@tabular*}
%    In order to facilitate complete \Lenv{tabular} environments to be
%    in a cell of a \Lenv{supertabular} environment we need to adapt
%    the definition of the orginal environments somewhat. For the
%    inner \Lenv{tabular} a number of definitions need to be
%    restored. 
% \changes{v4.0i}{1997/09/18}{Added \cs{noindent}}
%    \begin{macrocode}
\def\inner@tabular{%
  \ST@restore
  \let\\\@oldcr
  \noindent
  \org@tabular}
\@namedef{inner@tabular*}{%
  \ST@restore
  \let\\\@oldcr
  \noindent
  \csname org@tabular*\endcsname}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
% \begin{macro}{\ST@cr}
%    This macro is called by each |\\| inside the tabular environment.
%    It updates the estimate of the amount of space left on the
%    current page and starts a new page if necessary.
%    \begin{macrocode}
\def\ST@cr{%
  \noalign{%
    \ifnum\ST@pboxht<\ST@lineht
%    \end{macrocode}
%    If there is a non-empty line, but an empty parbox, then
%    |\ST@pboxht| might be non-zero, but too small thereby breaking
%    the algorithm. Therefor we estimate the height of the line to be
%    |\ST@lineht| in this case.
%    \begin{macrocode}
      \global\advance\ST@pageleft -\ST@lineht
%    \end{macrocode}
%    And we store that fact in |\ST@prevht|.
% \changes{v4.0g}{1997/04/12}{store the height of the previous line in
%    \cs{ST@prevht}} 
%    \begin{macrocode}
      \global\ST@prevht\ST@lineht
    \else
%    \end{macrocode}
%    When the parbox was not empty we take into account its height
%    (plus a bit extra).
% \changes{v4.0g}{1997/04/12}{Also take \cs{ST@stretchht} into
%    account and store the height of the parbox in \cs{ST@prevht}}
% \changes{v4.1f}{2019/03/01}{Use \cs{ST@trace@cr} instead of
%    \cs{ST@trace}} 
% \changes{v4.1g}{2020/02/02}{\cs{ST@stretchht} is no longer needed}
%    \begin{macrocode}
     \ST@trace@cr\thr@@{Added par box with height \the\ST@pboxht}%
      \global\advance\ST@pageleft -\ST@pboxht
      \global\advance\ST@pageleft -0.1\ST@pboxht
      \global\ST@prevht\ST@pboxht
      \global\ST@pboxht\z@
    \fi
%    \end{macrocode}
%    |\ST@toadd| is the value of the optional argument of |\\|.
%    \begin{macrocode}
    \global\advance\ST@pageleft -\ST@toadd
    \global\ST@toadd=\z@
    \ST@trace@cr\thr@@{Space left for tabular: \the\ST@pageleft}%
  }
%    \end{macrocode}
%    This line is necessary because the tablehead has to be inserted
%    *after* the following |\if\else\fi|-clause. For this purpose
%    |\ST@next| is used by |\ST@newpage|. But we need to make sure
%    that |\ST@next| is not undefined when |\ST@newpage| is \emph{not}
%    called. In the middle of tableprocessing it shoud be an *empty*
%    macro (*not* |\relax|).%  (15.2.91)
% \changes{v4.1e}{2001/08/21}{Moved the default definition of
%    \cs{ST@next} out of the \cs{if} clause} 
%    \begin{macrocode}
  \noalign{\global\let\ST@next\@empty}%
%    \end{macrocode}
%    When the |\ST@pageleft| has become negative, the last row was so
%    high that the supertabular doesn't fit on the current page after
%    all. In this case we will skip the current page and start at the
%    top of the next one; otherwise \TeX\ will move this part of the
%    table to a new page anyway, probably with a message about an
%    overfull |\vbox|.
%    \begin{macrocode}
  \ifnum\ST@pageleft<\z@
    \ST@skippage
  \else
%    \end{macrocode}
%    When there is not enough space left on the current page, we start
%    a new page. To compute the amount of space need we use the
%    height of the previous line (|\ST@prevht|) as an estimation of
%    the height of the next line. If we are processing a
%    \Lenv{mpsupertabular} we need to take the height of the footnotes
%    into account. 
% \changes{v4.0g}{1997/04/12}{Leave room for both \cs{ST@tailht}
%    \emph{and} \cs{ST@prevht}} 
% \changes{v4.1a}{1997/09/19}{Take care of space needed for 
%    footnotes and footnoterule} 
%    \begin{macrocode}
    \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}
    \ifnum\ST@pageleft<\@tempdima
      \ST@newpage
    \fi
  \fi
  \ST@next}
%    \end{macrocode}
% \end{macro}
%
%  \begin{macro}{\ST@skipfirstpart}
% \changes{v4.0d}{1997/03/06}{Added new macro.}
% \changes{v4.0e}{1997/04/09}{Renamed from \cs{ST@skippage}}
%    This macro skips the current page and moves the entire
%    supertabular that has been built up sofar to the next page.
%    \begin{macrocode}
\def\ST@skipfirstpart{%
  \noalign{%
    \ST@trace\tw@{Tabular too high, moving to next page}%
%    \end{macrocode}
%    In order for this to work properly we need to adapt the value of
%    |\ST@pageleft|. When this macro is called it has a negative
%    value. We should add the height of the next page to that
%    (|\@colroom|). From the result the `normal' height of the
%    supertabular should be substracted (|\@colroom| -
%    |\pagetotal|). This could be coded as follows:
%\begin{verbatim}
%      \ST@dimen\@colroom
%      \advance\ST@dimen-\pagetotal
%      \global\advance\ST@pageleft\@colroom
%      \global\advance\ST@pageleft-\ST@dimen
%\end{verbatim}
%    When you examine the code you will note that |\@colroom| is added
%    \emph{and} subtracted. Therefor the code above can be simplified
%    to:
%    \begin{macrocode}
    \global\advance\ST@pageleft\pagetotal
%    \end{macrocode}
%    Then we can set |\ST@pagesofar| to $0$ and start the new page.
%    \begin{macrocode}
    \global\ST@pagesofar\z@
    \newpage
%    \end{macrocode}
%
%    Finally we make sure that this macro can only be executed once
%    for each supertabular by changing the definition of
%    |\ST@skippage|. 
% \changes{v4.0e}{1997/04/09}{Make sure that only the first part of a
%    supertabular can be moved to the next page.} 
%    \begin{macrocode}
    \global\let\ST@skippage\ST@newpage
    }}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\ST@newpage}
% \changes{v3.7b}{1994/05/16}{Added macro, split off from
%    \cmd\ST@cr}
%    This macro performs the actions necessary to start a new page.
%    \begin{macrocode}
\def\ST@newpage{%
  \noalign{\ST@trace\tw@{Starting new page, writing tail}}%
%    \end{macrocode}
%    Output |\tabletail|, close the tabular environment, close a
%    \Lenv{mnipage} if necessary, output all material and start a
%    fresh new page. 
% \changes{v4.1a}{1997/09/19}{Close minipage if we are in 
%    \Lenv{mpsupertabular}}
%    \begin{macrocode}
  \@tabletail
  \ifST@star
    \csname endtabular*\endcsname
  \else
    \endtabular
  \fi
  \ifST@mp
    \endminipage
  \fi
%    \end{macrocode}
%
%    Then we make sure that the macro |\ST@skippage| can no longer be
%    executed for this supertabular by changing the definition of it.
% \changes{v4.0d}{1997/03/06}{Use \cs{org@tabular} instead of
%    \cs{tabular}} 
% \changes{v4.0e}{1997/04/09}{Make sure that only the first part of a
%    supertabular can be moved to the next page.} 
% \changes{v4.0f}{1997/04/11}{Use \cs{org@tabular*} instead of
%    \cs{tabular*}}
% \changes{v4.0i}{1997/09/18}{Added \cs{noindent}}
% \changes{v4.1a}{1997/09/19}{Open new minipage if we are in 
%    \Lenv{mpsupertabular}}
%    \begin{macrocode}
  \global\let\ST@skippage\ST@newpage
  \newpage\@calnextpageht
  \let\ST@next\@tablehead
  \ST@trace\tw@{writing head}%
  \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}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \Finale
\endinput