home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0500 / CCE_0544.ZIP / CCE_0544 / SUPERTAB / SUPERTAB.DOC next >
Text File  |  1992-05-31  |  22KB  |  470 lines

  1. % @stylefile{Super tabular
  2. % shortpackagename = {supertab},
  3. % longpackagename  = {supertabular},
  4. % baseformats      = {\LaTeX 2.09},
  5. % version          = {3.6f},
  6. % date             = {1992-03-11},
  7. % author           = {Theo Jurriens, 
  8. %                     TAJ@HGRRUG5, 
  9. %                     P.O Box 800, 
  10. %                     9700 AV Groningen},
  11. % abstract         = {This file provides the supertabular environment, which
  12. %                     is an extension to the standard tabular environment.
  13. %                     Large tabulars are automatically split across pages.
  14. %                     Seperate commands for the table-head and table-tail
  15. %                     are provided, in order to repeat these on each page.}
  16. % infauthor        = {Johannes Braams,
  17. %                     J.L.Braams@research.ptt.nl,
  18. %                     PTT Research,
  19. %                     P.O. Box 421,
  20. %                     2260 AK Leidschendam}
  21. % infdate           = {1990-10-16}}
  22. %
  23. %----------------------------------------------------------------------------
  24. %
  25. % supertabular sty
  26. % original idea:  Theo Jurriens 1988
  27. %                 TAJ@hgrrug5        P.O Box 800, 9700 AV Groningen
  28. %
  29. % revised by:     Johannes Braams
  30. %                 JL_Braams@pttrnl.nl   PTT Research Leidschendam (NL)
  31. %
  32. % 11.02.92  - Bug found by Michael Heissmeier when p{...} is used.
  33. % V 3.6f      A change in LaTeX.tex didn't find its way into supertabular.
  34. % 01.08.91  - Take height of tabletail into account when computing the
  35. % V 3.6e      maximum tableheight; add tolerance on first (partial) page
  36. %             of the supertabular.
  37. % 27.06.91  - Cured bug that made the first part of the table one line
  38. % V 3.6d      shorter than the others. Appeared when supertabular was
  39. %             used in a twocolumn environment.
  40. % 26.06.91  - Made \@process@tablecaption a global macro. Previous caption
  41. % V 3.6c      turned up on a table without one.
  42. % 27.05.91  - Replaced \clearpage with \newpage to make supertabulars work
  43. % V 3.6b      in a twocolumn environment. This also prevents all floats
  44. %             from being printed.
  45. % 15.02.91  - Because of the check for the use of tablefirsthead the
  46. % V 3.6a      combination of an \hline in the head and an \hline as the first
  47. %             thing in the data went wrong. The \futurelet in the definition
  48. %             of \hline found \fi instead of \hline, so no \doublerulesep
  49. %             was added.
  50. %             Also had to modify the way the environments were defined.
  51. %             The blank space (from the CR after the argument of \supertabular)
  52. %             has to be gobbled. This can only be done using a construction
  53. %             like \def\command#1 {...}. So removed the use of \newenvironment
  54. % 04.02.91  - Added the commands \topcaption, \bottomcaption and \tablecaption 
  55. % V 3.6       to include a caption within the supertabular environment. The
  56. %             default behaviour is to put the caption before the actual start
  57. %             of the table.
  58. %           - Also added \tablefirsthead and \tablelasttail to let the
  59. %             user specify a different head for the first page of the table
  60. %             and for consecutive pages as well as different tails for first
  61. %             pages and the last one. If these commands are not used, the
  62. %             default behaviour will be to use the value of \tablehead end
  63. %             \tabletail
  64. %           - Removed the need for the \noalign{\global\let\\=\@stabularcr}
  65. %             commands by storing and resetting \@stabularcr
  66. %
  67. % 16.10.90  Added the supertabular* environment that was in an earlier
  68. % V 3.5     version (2.0) by the original author
  69. %           Reintroduced the version numbering
  70. %
  71. % revised by:     Gabriele Kruljac
  72. %                 kruljac@ds0mpi11   Max-Planck-Institute Stuttgart
  73. %
  74. %
  75. % 06.06.89  Correction: now care is taken of probably existing onecolumn
  76. %           head (title or tables ...) in twocolumn sty.
  77. %
  78. % 10.05.89  Correction: the new \\ definition has been added to the
  79. %           begin of each `sub'-tabular
  80. %           Added: algorithm to produce the tabulars in twocolumn style
  81. %
  82. % 06.04.89  Correction: put \global statement in \end{supertabular}
  83. %           into \noalign
  84. %
  85. % 22.02.89  Correction: restore the original meaning of \\ with
  86. %           \end{supertabular}
  87. %
  88. % (Feb 89) The whole algorithm has been changed, so that I can use
  89. %          the most features of a normal tabular:
  90. %          \\  for new line, including  \\[#1]
  91. %          p{...} in the preamble ...
  92. %          Account is taken to \baselinestretch and \arraystretch
  93. %         -I'm not counting the lines because of too much rounding errors
  94. %          but instead I add the (estimated) used space in pt.
  95. %         -The tablehead is taken into this algorithm of proofing, so
  96. %          I really know how much space the head uses.
  97. %         -When no p-arg is given I add a variable \midlineheight to
  98. %          calculate the used space. To calculate \midlineheight I
  99. %          take the \baselineskip, which is active when the supertabular
  100. %          starts (\baselineskip includes the \value of \baselinestretch)
  101. %          and multiply it with \arraystretch.
  102. %         -When a p-arg is given the text will be stored in a box. So
  103. %          I know the height I have to add. Also I reduce the maximum
  104. %          pagesize, so that the last parbox on a page can get up to
  105. %          max 4 lines without producing an overfull vbox.
  106. %         -To do so I had to make some additions to LaTeX's tabular
  107. %          commands. These new commands got a leading `s'.
  108. %
  109. %          Weak points:
  110. %          -When the material of a normal entry (not a p-arg) becomes
  111. %           larger than the estimated \midlineheight, overfull vboxes
  112. %           will be produced at all.
  113. %          -When the last p-arg on a page gets more than 4 lines
  114. %           (probably even more than 3 lines) it will result in an
  115. %           overfull vbox.
  116. %           Also some combinations of \baselinestretch \arraystretch and
  117. %           a large font may lead to one line too much.
  118. %          -if accidentally the last line of the tabular produces
  119. %           a newpage, on the next page the tabletail will be written
  120. %           immediately after the tablehead. Depending on the contents
  121. %           this may result in an error message regarding misplaced
  122. %           \noalign.
  123. %
  124. %           A quick but not very elegant solution: shrink \maxsize by
  125. %           \noalign{\global\maxsize=...pt} after the first \\ of the
  126. %           supertabular.
  127. %
  128. %------------------------------------------------------------------------------ 
  129. % Added the user-commands \topcaption and \bottomcaption which set the boolean
  130. % @topcaption to determine where to put the tablecaption. The default
  131. % is to put the caption on the top of the table
  132. %
  133. \newif\if@topcaption \@topcaptiontrue
  134. \def\topcaption{\@topcaptiontrue\tablecaption}
  135. \def\bottomcaption{\@topcaptionfalse\tablecaption}
  136. %
  137. % Added the command \tablecaption, with the use of the definition
  138. % of the \caption and \@caption commands from latex.tex.
  139. % This command has to function exactly like \caption does except it
  140. % has to store its argument (and the optional argument) for later
  141. % processing WITHIN the supertabular environment
  142. % JB
  143. %
  144. \long\def\tablecaption{\refstepcounter{table} \@dblarg{\@xtablecaption}}
  145. \long\def\@xtablecaption[#1]#2{%
  146.   \long\gdef\@process@tablecaption{\@stcaption{table}[#1]{#2}}}
  147. \global\let\@process@tablecaption\relax
  148. %
  149. %
  150. % This is a redefinition of LaTeX's \@caption, \@makecaption is
  151. % called within a group so as not to return to \normalsize globally.
  152. % also a fix is made for the `feature' of the \@makecaption of article.sty and
  153. % friends that a caption ALWAYS gets a \vskip 10pt at the top and NONE at the
  154. % bottom. If a user wants to precede his table with a caption this results
  155. % in a collision.
  156. %
  157. \long\def\@stcaption#1[#2]#3{\par%
  158.     \addcontentsline{\csname ext@#1\endcsname}{#1}%
  159.         {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}
  160.   \begingroup
  161.     \@parboxrestore
  162.     \normalsize
  163.     \if@topcaption \vskip -10pt \fi % 'fix' 
  164.     \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  165.     \if@topcaption \vskip 10pt \fi % 'fix' 
  166.   \endgroup}
  167. %
  168. %                             % \tablehead activates the new tabular \cr
  169. %                             % commands
  170. \def\@tablehead{}
  171. \def\tablehead#1{\gdef\@tablehead{#1}}
  172. \def\tablefirsthead#1{\gdef\@table@first@head{#1}}
  173. %+
  174. %     If the user uses an extra amount of tabular-data (like \multicolumn)
  175. %     in \verb=\tabletail= \TeX\ starts looping because of the definition
  176. %     of \verb=\nextline=. So make \verb=\\= act like just a \verb=\cr=
  177. %     inside this tail to prevent the loop. 
  178. %     Save and restore the value of \verb=\\=
  179. %-
  180. \def\@tabletail{}
  181. \def\tabletail#1{%
  182.     \gdef\@tabletail{\noalign{\global\let\@savcr=\\\global\let\\=\cr}%
  183.                      #1\noalign{\global\let\\=\@savcr}}}
  184. \def\tablelasttail#1{\gdef\@table@last@tail{#1}}
  185. \newdimen\maxsize            % maximum pagesize
  186. \newdimen\actsize            % actual pagesize
  187. \newdimen\twocolsize         % needed for correct max height if twocolumn
  188. \newdimen\parboxheight       % height plus depth of a parbox-argument
  189. \newdimen\addspace           % stores the value of \\[#1]
  190. \newdimen\midlineheight      % estimated size of a normal line
  191. \newdimen\pargcorrection     % to set page height tolerance if p-arg
  192. \newdimen\computedimens      % computation variable
  193. \newbox\tabparbox
  194. %         %%%%  Redefine original LaTeX tabular \cr commands. %%%%
  195. %         %%%%  New tabular \cr commands get a leading `s'    %%%%
  196. %                             % Insert  \nextline command for counting
  197. \def\@stabularcr{{\ifnum0=`}\fi\@ifstar{\@sxtabularcr}{\@sxtabularcr}}
  198. \def\@sxtabularcr{\@ifnextchar[{\@sargtabularcr}%
  199.                  {\ifnum0=`{\fi}\cr\nextline}}
  200. %                             % contents of command unchanged
  201. \def\@sargtabularcr[#1]{\ifnum0=`{\fi}\ifdim #1>\z@
  202.     \unskip\@sxargarraycr{#1}\else \@syargarraycr{#1}\fi}
  203. %                             % here copy the value #1 of [ ] of \\
  204. %                             % to \addspace
  205. \def\@sxargarraycr#1{\@tempdima #1\advance\@tempdima \dp \@arstrutbox%
  206.     \vrule \@height\z@ \@depth\@tempdima \@width\z@ \cr%
  207.     \noalign{\global\addspace=#1}\nextline}
  208. %                             % command will be called when \\[0pt]
  209. \def\@syargarraycr#1{\cr\noalign{\vskip #1\global\addspace=#1}\nextline}
  210. %         %%%%  Redefine original LaTeX p-arg commands.       %%%%
  211. %         %%%%  New commands get a leading `s'                %%%%
  212. %                                      % reduce maximum pagesize to have
  213. %                                      % a small tolerance for last entry
  214. \def\@sstartpbox#1{\global\advance\maxsize by -\pargcorrection
  215.                    \global\pargcorrection=0pt
  216. %                                      % put text into box to save height
  217.                    \setbox\tabparbox%
  218.                           \vtop\bgroup\hsize#1\@arrayparboxrestore}
  219. % 11/03/92 JB: The following change didn't find its way into the 
  220. %              \@sendpbox command. This caused a difference in linespacing
  221. %              between a supertabular and a normal tabular. 
  222. % \def\@endpbox{\unskip\strut\par\egroup\hfil}
  223. % % 14 Jan 89: Def of \@endpbox changed from
  224. % %    \def\@endpbox{\par\vskip\dp\@arstrutbox\egroup\hfil}
  225. % % so vertical spacing works out right if the last line of a `p' entry
  226. % % has a descender.
  227. \def\@sendpbox{\unskip\strut\par\egroup%
  228.                \computedimens=\ht\tabparbox%
  229.                \advance\computedimens by \dp\tabparbox%
  230.                \ifnum\parboxheight<\computedimens
  231.                   \global\parboxheight=\computedimens
  232.                \fi
  233.                \computedimens=0pt
  234.                \box\tabparbox\hfil}
  235. %         %%%%  Here start really new supertabular commands   %%%%
  236. %                                 % estimate height of normal line
  237. %                                 % regarding \array- and \baselinestretch
  238. \def\calmidlineheight{\midlineheight=\arraystretch \baslineskp
  239.                       \global\advance\midlineheight by 1pt
  240.                       \global\pargcorrection=4\midlineheight}
  241. \def\calpage{\global\actsize=\pagetotal  % where am I on the actual page?
  242.              \twocolsize=\textheight            %  added 06.06.89
  243.              \advance\twocolsize by -\@colroom  %        "
  244.              \advance\actsize by \twocolsize    %        "
  245.              \global\advance\actsize by \midlineheight
  246.              \maxsize=\textheight        % start a new page when 90% of
  247.              \multiply \maxsize by 9     % the page are used
  248.              \divide\maxsize by 10
  249. % Add a litle tolerance on the firsat (partial) page V3.6e
  250.              \advance\actsize 2\midlineheight
  251.              \ifnum\actsize > \maxsize
  252.                    \clearpage
  253.                    \global\actsize=\pagetotal
  254.              \fi
  255.              \maxsize=\textheight       % now set \maxsize with tolerance
  256. %+
  257. %     measure the height of the tabletail and substract from \maxsize
  258. %-
  259.              \setbox\@tempboxa=\vbox{\@arrayparboxrestore%
  260.                 \begin{tabular}{\tableformat}\@tabletail\end{tabular}}
  261.              \global\advance\maxsize by-\ht\@tempboxa}
  262.                              % Here is the definition of supertabular
  263. % modified JB (15.2.91)
  264. \def\supertabular#1 {%           % before it was \edef\tableformat,
  265. %                                % but gave error with @{\hspace{..}} !
  266.     \def\tableformat{\string#1} % store preamble
  267.     \global\starfalse % remember this is the normal version
  268. %                                 % Check if we have to insert a caption
  269.     \if@topcaption\@process@tablecaption
  270.     \fi
  271. %                                 % save old \\ moved from below V3.6e
  272.     \global\let\@oldcr=\\
  273.     \def\baslineskp{\baselineskip}
  274.     \calmidlineheight% estimate height of a normal line
  275.     \calpage         % calculate max. pagesize and startpoint
  276. %                                 % save old \@tabularcr
  277.     \let\@@tabularcr\@tabularcr%             Added JB 4/2/91
  278. %                                % Now insert the definition of \@stabularcr
  279.     \let\@tabularcr\@stabularcr
  280. %                                 % activate new parbox algorithm
  281.     \let\@@startpbox=\@sstartpbox
  282.     \let\@@endpbox=\@sendpbox
  283. %
  284. %    Moved the check for the use of \tablefirsthead to befor the start of
  285. %    the tabular environment in order to make the \futurelet inside \hline
  286. %    do its work correctly (15.02.91)
  287. %
  288.     \ifx\@table@first@head\undefined
  289.         \let\@@tablehead=\@tablehead
  290.     \else
  291.         \let\@@tablehead=\@table@first@head
  292.     \fi%                                     Added JB 4/2/91
  293. %                                 % start normal tabular environment
  294.     \begin{tabular}{\tableformat}%
  295.     \@@tablehead}%   Added JB 15/2/91
  296. %
  297. %                                 % this is \end{supertabular}
  298. \def\endsupertabular{%
  299.     \ifx\@table@last@tail\undefined%
  300.         \@tabletail%
  301.     \else%
  302.         \@table@last@tail%
  303.     \fi%                                     Added JB 4/2/91
  304. %removed JB                \noalign{\global\let\\=\@oldcr}%
  305. %   \let\@@startpbox=\@startpbox%
  306. %   \let\@@endpbox=\@endpbox%
  307.     \end{tabular}
  308. %                                 % restore old \@tabularcr
  309.     \let\@tabularcr\@@tabularcr             % Added JB 4/2/91
  310. %                                 % Check if we have to insert a caption
  311.     \if@topcaption
  312.     \else
  313.         \@process@tablecaption
  314. %                                 % restore to default behaviour
  315.         \@topcaptiontrue
  316.     \fi
  317. %+
  318. %    Restore the meaning of \verb=\\= to the one it had before the start
  319. %    of this environment. Also re-initialize some control-sequences
  320. %-
  321.     \global\let\\=\@oldcr
  322.     \let\@table@first@head\undefined        % For the next ocurrence
  323.     \let\@table@last@tail\undefined         % of this environment   
  324.     \global\let\@process@tablecaption\relax
  325. }
  326. %                             % Here is the definition of supertabular*
  327. \newif\ifstar
  328. \newdimen\tabularwidth
  329. \@namedef{supertabular*}#1#2 {% modified JB (15.2.91)
  330. %                                 % before it was \edef\tableformat,
  331. %                                 % but gave error with @{\hspace{..}} !
  332.     \def\tableformat{\string#2} % store preamble
  333.     \tabularwidth=#1 % The total width of the tabular
  334.     \global\startrue % remember this is the *-version
  335. %                                 % Check if we have to insert a caption
  336.     \if@topcaption\@process@tablecaption\fi
  337. %
  338.     \def\baslineskp{\baselineskip}
  339.     \calmidlineheight% estimate height of a normal line
  340.     \calpage         % calculate max. pagesize and startpoint
  341. %                                 % save old \@tabularcr
  342.     \let\@@tabularcr\@tabularcr%              Added JB 4/2/91
  343. %                                % Now insert the definition of \@stabularcr
  344.     \let\@tabularcr\@stabularcr%              Added JB 4/2/91
  345. %                                 % save old \\
  346.     \global\let\@oldcr=\\
  347. %                                 % activate new parbox algorithm
  348.     \let\@@startpbox=\@sstartpbox
  349.     \let\@@endpbox=\@sendpbox
  350. %
  351. %    The same modification as for \tabular 15.2.91
  352.     \ifx\@table@first@head\undefined
  353.         \let\@@tablehead\@tablehead
  354.     \else
  355.         \let\@@tablehead\@table@first@head
  356.     \fi%                                     Added JB 4/2/91
  357. %                                 % start normal tabular environment
  358.     \begin{tabular*}{\tabularwidth}{\tableformat}%
  359. %
  360. %removed JB                \noalign{\global\let\\=\@stabularcr}
  361.     \@@tablehead}%
  362. %                                 % this is \end{supertabular*}
  363. \@namedef{endsupertabular*}{%
  364.     \ifx\@table@last@tail\undefined%
  365.         \@tabletail%
  366.     \else%
  367.         \@table@last@tail%
  368.     \fi%                                     Added JB 4/2/91
  369. %removed JB                \noalign{\global\let\\=\@oldcr}%
  370.     \end{tabular*}
  371. %                                 % restore old \@tabularcr
  372.     \let\@tabularcr\@@tabularcr
  373. %               \let\@@startpbox=\@startpbox%
  374. %               \let\@@endpbox=\@endpbox%
  375.                                  % Check if we have to insert a caption
  376.     \if@topcaption
  377.     \else
  378.         \@process@tablecaption
  379.                                  % restore to default behaviour
  380.         \@topcaptiontrue
  381.     \fi
  382. %+
  383. %    Restore the meaning of \verb=\\= to the one it had before the start
  384. %    of this environment. Also re-initialize some control-sequences
  385. %-
  386.     \global\let\\=\@oldcr
  387.     \let\@table@first@head\undefined        % For the next ocurrence
  388.     \let\@table@last@tail\undefined         % of this environment   
  389.     \global\let\@process@tablecaption\relax}
  390. \def\nextline{%           %%% algorithm to calculate the pagebreaks %%%
  391.     \noalign{\ifnum\parboxheight<\midlineheight
  392. % V3.6e, non-empty line, but empty parbox, then \parboxheight might
  393. % be non-zero, but too small thereby breaking the algorithm.
  394. %                                 % if no p-arg add `normal' line height
  395.                    \advance\actsize by \midlineheight
  396. %                                      % \addspace is value #1 of \\[#1]
  397.                    \global\advance\actsize by \addspace
  398.              \else
  399. %                                 % if p-arg add height of box and more
  400.                    \global\advance\actsize by \parboxheight
  401.                    \divide\parboxheight by 11\relax
  402.                    \global\advance\actsize by \parboxheight%
  403.                    \global\parboxheight=0pt
  404.              \fi
  405.              \global\addspace=0pt}%
  406. %                                      % when page becomes full:
  407.     \ifnum\actsize<\maxsize
  408. %
  409. %    This line is necessary because the tablehead has to be inserted *after*
  410. %    the \if\else\fi-clause. For this purpose \next is used. In the middle
  411. %    of tableprocessing it shoud be an *empty* macro (*not* \relax).
  412. %    (15.2.91)
  413.     \noalign{\global\let\next\@empty}
  414.     \else
  415. %                                      % output \tabletail, close tabular
  416. %                                      % output all material and start a
  417. %                                      % fresh new page
  418.          \@tabletail
  419.          \ifstar%                     % Added 16-10-90
  420.            \end{tabular*}%
  421.          \else%
  422.            \end{tabular}%
  423.          \fi
  424.          \if@twocolumn%                        % added 10.05.89
  425.             \if@firstcolumn%                   %
  426.                \newpage%                       %
  427.             \else%                             %
  428.                \clearpage%                     %
  429.             \fi%                               %
  430.             \twocolsize=\textheight%           % added 06.06.89
  431.             \advance\twocolsize by -\@colroom% %       "
  432.             \global\actsize=\twocolsize%       %       "
  433. % The following lined added 27/6/91 like in the definition of \calpage
  434.             \global\advance\actsize by \midlineheight
  435.          \else                                 %
  436.             \clearpage                         %
  437.             \global\actsize=\midlineheight%
  438.          \fi                                   %
  439.          \let\next\@tablehead%                 % Added 15.2.91
  440.          \ifstar%                              % Added 16-10-90
  441.            \begin{tabular*}{\tabularwidth}{\tableformat}%
  442.          \else%
  443.            \begin{tabular}{\tableformat}%
  444.          \fi%
  445. %removed JB         \noalign{\global\let\\=\@stabularcr}  % added 10.05.89
  446. %removed JB         \@tablehead%
  447.     \fi\next}%                                % Added \next 15.2.91
  448.