home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / inputs / supertab / supertabular.doc < prev    next >
Text File  |  1992-07-10  |  23KB  |  507 lines

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