[comp.text.tex] Help on tabular environment

bed_gdg@NIORD.SHSU.EDU ("George D. Greenwade") (06/04/91)

On Tue, 4 Jun 91 08:37:20 CDT, Max Hailperin <max@nic.gac.edu> forwarded a
request from and reply to Bernd Bachmann <bachmann@dfki.uni-kl.de> to 
LaTeX-help-toughies@cs.stanford.edu.  I am posting back to these addresses
and to INFO-TeX/comp.text.tex.

From: Max Hailperin <max@nic.gac.edu>

> I was only able to suggest supertab.sty in response to the following
> query, and that doesn't do the full job (it assumes each line is the
> standard size, and hence won't cope with the parboxes).  Does anyone
> have a better solution to the problem below?

> Date:     Fri, 31 May 91 13:26:44 MET DST
> From: Bernd Bachmann <bachmann@dfki.uni-kl.de>
> To: LaTeX-help@sumex-aim.stanford.edu
> Subject:  Help on tabular environment (already mailed on Mon, 13 May 91)
> Organization:  German Research Center for AI (DFKI)

> Hi there,

> is there an easy way (hack or styles) to get tables (in the tabular
> environment) automatically, dynamically separated which are longer
> than the remaining space of the current page (longer than a page at
> all)? A repeating header line for each page should also be provided,
> though not necessary. Additionally, there are columns in the table
> which are defined as parboxes (p{...cm}) with an abitrary number of
> text lines!

> Thanks in advance,

> - Bernd

There is a style file available from FILESERV@SHSU.BITNET named LONGTABLE
which (sort of) handles p-width columns in a {longtable} environment
written by David Carlisle <carlisle@uk.ac.man.cs> dated 20/12/90.  It is
similar to {supertabular}, but does a few other things as well (such as
stepping and using the table counter, providing a caption, etc.).  The main
limitation on p-width columns is that they are not split across pages
(properly counted w.r.t. lines used, but splits only occur on \hlines and
line breaks).  It can be used with small memory systems as well as big TeX
by controlling a chunk size variable provided in the style file.  David was
nice enough to provide an overview TeX file for instructions on use
(including a discussion of the chunk size variable).

To retrieve both LONGTABLE.STY and LONGTABLE.TEX, include the command:
SENDME STY.LONGTABLE*
in the body of a mail message to FILESERV@SHSU.BITNET.  As always, please
note the syntax reversal used on FILESERV's style archive, and (in this
case) note the use of the "*" wildcard to get both files.

Regards,   George
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
George D. Greenwade, Ph.D.                            Bitnet:  BED_GDG@SHSU
Department of Economics and Business Analysis         THEnet: SHSU::BED_GDG
College of Business Administration                    Voice: (409) 294-1266
P. O. Box 2118                                        FAX:   (409) 294-3612
Sam Houston State University               Internet: bed_gdg@Niord.SHSU.edu
Huntsville, TX 77341                      bed_gdg%SHSU.decnet@relay.the.net
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

glenn@network.ucsd.edu (Glenn Sueyoshi) (06/06/91)

In article <009499D5.177367A0.6104@Niord.SHSU.edu> bed_gdg@NIORD.SHSU.EDU 
("George D. Greenwade") writes:

>There is a style file available from FILESERV@SHSU.BITNET named LONGTABLE
>which (sort of) handles p-width columns in a {longtable} environment
>written by David Carlisle <carlisle@uk.ac.man.cs> dated 20/12/90.  It is
>similar to {supertabular}, but does a few other things as well (such as
>stepping and using the table counter, providing a caption, etc.).  

I'd like to put in a qualified plug for this .sty.  The main problem 
with the supertabular.sty and friends is that there does not appear
to be support for all of the numbering and cross-referencing provided
under table.

I say qualified because while I've grabbed the files and run the test
program and see how it should work in principal, I can't seem to get
it to line up the column widths properly.  The documentation says
that one should enable (uncomment out) out the \setlongtables
command and re-run, which I have (twice), but I still get columns 
which don't align.

I'm running LaTeX 2.09 <7 December 1989> under TeX 3.0 and have the
Mittelbach et al. font selection scheme installed.  I can send the
.log and .aux files to any who care, but let me note that when I
run the file, TeX DOES NOT complain about redefined column widths.

Let me say that if I can get this to work, it should solve the main
problems with table/page breaking and I would recommend the style
with few reservations.

>The main
>limitation on p-width columns is that they are not split across pages
>(properly counted w.r.t. lines used, but splits only occur on \hlines and
>line breaks).  

Can't see how TeX could do any better.  My feeling is that so long as
the lines are properly counted, that's the best that you're going to
get using a box oriented system like TeX.

If only I could get the boxes to line up.  Any thoughts George?  
If not, I'll try to get a hold of David Carlisle directly.
Thanks.

Glenn

piet@cs.ruu.nl (Piet van Oostrum) (06/06/91)

> I was only able to suggest supertab.sty in response to the following
> query, and that doesn't do the full job (it assumes each line is the
> standard size, and hence won't cope with the parboxes).  Does anyone
> have a better solution to the problem below?

The newest version of supertab does have support for parboxes.
-- 
Piet* van Oostrum, Dept of Computer Science, Utrecht University,
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
Telephone: +31 30 531806   Uucp:   uunet!mcsun!ruuinf!piet
Telefax:   +31 30 513791   Internet:  piet@cs.ruu.nl   (*`Pete')

dmjones@theory.lcs.mit.edu (David M. Jones) (06/14/91)

In article <5434@network.ucsd.edu>, glenn@network (Glenn Sueyoshi) writes:

>I say qualified because while I've grabbed the files and run the test
>program and see how it should work in principal, I can't seem to get
>it to line up the column widths properly.  The documentation says
>that one should enable (uncomment out) out the \setlongtables
>command and re-run, which I have (twice), but I still get columns 
>which don't align.
>
>I'm running LaTeX 2.09 <7 December 1989> under TeX 3.0 and have the
>Mittelbach et al. font selection scheme installed.

Since I haven't seen any response to this, I'll take the liberty of
burdening the net with my analysis.

The culprit is the M&S font selection scheme.  In particular,
lfonts.new redefines \@tabclassz as follows:

   \def\@tabclassz{\ifcase \@lastchclass
          \@acolampacol \or \@ampacol \or
          \or \or \@addamp \or
          \@acolampacol \or
          \@firstampfalse \@acol \fi
    \edef\@preamble{\@preamble{%  <===== extra open curly brace
      \ifcase \@chnum
        \hfil\ignorespaces\@sharp\unskip\hfil
       \or \ignorespaces\@sharp\unskip\hfil
       \or \hfil\hskip\z@
          \ignorespaces\@sharp\unskip\fi}}}%  <======= extra close curly

(Note that this is the only change in \@tabclassz.)

As you can see, this adds an extra level of braces around each
template in the \halign \@preamble, so you get something like

    \hskip \tabcolsep {\ignorespaces \@sharp \unskip \hfil }\hskip \tabcolsep 

instead of

    \hskip \tabcolsep \ignorespaces \@sharp \unskip \hfil \hskip \tabcolsep

Now, longtable.sty counts the number of columns in a table essentially
by counting the number of \@sharp's in the preamble.  It does this by
taking the preamble apart with a macro invoked something like this:

        \macro#1\@sharp

But, since the \@sharp's are now inside braces, this fails.  The
result is that the number of columns \LT@cols is set to 0, and this
causes trouble for the \LT@blank@row command, which uses \LT@cols to
determine how many "\omit"s is should put in the blank line that is
used to measure the length of the columns in the table and store that
information in the .aux file.  The final result of this is that, e.g.,
you get

        \gdef \LT@i{\omit \kern 166pt}

instead of

        \gdef \LT@i{\omit \kern 166pt&\omit \kern 42pt&\omit \kern 34pt}

in the .aux file.

I'm not sure what the correct solution is, since I don't know why the
extra level of braces was added to \@tabclassz (I don't have a copy of
lfonts.doc).  I don't know what would happen if we simply changed the
definition back to the original one, but I assume something would go
wrong somewhere.  The alternative seems to be to redefine the column
counting routine to handle the new type of preamble, but I'm not quite
sure how to do that.  (Perhaps we should just redefine \@mkpream to
count the columns while it is constructing the preamble?)  Any wizards
have any ideas?  Would anyone care to check my analysis?  I'll be glad
to provide more details to any interested party.
------------------------------------------------------------------------------
David M. Jones                                 |"What we've just seen's
ARPANET: dmjones@athena.mit.edu                | A pathetic display
UUCP: ...!mit-eddie!mit-athena!dmjones         | By a man who's
USmail: 3 Ames Street; Cambridge, MA 02139     | Beginning to crack."
------------------------------------------------------------------------------

dmjones@theory.lcs.mit.edu (David M. Jones) (06/15/91)

I apologize if this goes out more than once.  The local news machine
has been flaky, and I tried to send from another host, but I don't
think it worked.

In article <1991Jun14.140857.25984@mintaka.lcs.mit.edu> I wrote:

>I'm not sure what the correct solution is [...] (Perhaps we should
>just redefine \@mkpream to count the columns while it is constructing
>the preamble?)

After a little thought, I decided that this was relatively painless,
since it involves modifying only the very macro which has been causing
us troubles, namely \@tablcassz.  At least, I think this is true.  Can
someone with a better understanding of the array code confirm (or
deny) that my solution is robust?  Diffs are included below.  I can
also send the entire new file to anyone who would prefer it that way.
------------------------------------------------------------------------------
David M. Jones                             |"I've just come across a fascinat-
17 Simpson Ave #1; Somerville, MA 02144    | ing piece in the Times.  Concerns
ARPANET: dmjones@theory.lcs.mit.edu        | the effects of lack of sleep 
UUCP: ...!mit-eddie!mit-athena!dmjones     | among the marginally sane."
------------------------------------------------------------------------------

*** longtable.sty	Fri Jun 14 14:09:04 1991
--- longtable.sty.ori	Fri Jun 14 14:13:23 1991
***************
*** 33,47 ****
  % The rest of the code is just window dressing to give the whole thing a more
  % LaTeX-like feel.
  
! % 6/14/91  Modifications by David M. Jones (dmjones@theory.lcs.mit.edu)
! %          Attempted to fix incompatbility with Mittelbach and
! %          Schoepf's font selection scheme caused by the redefinition
! %          of \@tabclassz in lfonts.new to add an additional level of
! %          braces inside the \halign preamble.
! 
  
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- 
  \newbox\LT@head%          Box for the table head (maybe not the first page).
  \newbox\LT@firsthead%     Box for the head of the first page of the table.
  \newdimen\LT@head@ht%     Height of the head (= max of \ht of the head boxes).
--- 33,40 ----
  % The rest of the code is just window dressing to give the whole thing a more
  % LaTeX-like feel.
  
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  \newbox\LT@head%          Box for the table head (maybe not the first page).
  \newbox\LT@firsthead%     Box for the head of the first page of the table.
  \newdimen\LT@head@ht%     Height of the head (= max of \ht of the head boxes).
***************
*** 81,104 ****
    \topskip\z@
    \@ifnextchar[{\LT@array}{\LT@array[x]}}
  
- %% 6/14/91 Redefined \@tabclassz to be consistent with the
- %% redefinition in Mittelbach and Schoepf's lfonts.new and to
- %% automatically count the columns as it is constructing the preamble.
- %% I think this is robust. -- David M. Jones (dmjones@theory.lcs.mit.edu)
- 
- \def\@tabclassz{\ifcase \@lastchclass
-        \@acolampacol \or \@ampacol \or
-        \or \or \@addamp \or
-        \@acolampacol \or
-        \@firstampfalse \@acol \fi
-  \advance\LT@cols\@ne           %% Added by dmjones
-  \edef\@preamble{\@preamble{%
-    \ifcase \@chnum
-      \hfil\ignorespaces\@sharp\unskip\hfil
-     \or \ignorespaces\@sharp\unskip\hfil
-     \or \hfil\hskip\z@
-        \ignorespaces\@sharp\unskip\fi}}}
- 
  \def\LT@array[#1]#2{\refstepcounter{table}%
    \xdef\LT@save@row{%
      \expandafter\noexpand\csname LT@\romannumeral\c@table\endcsname}%
--- 74,79 ----
***************
*** 111,122 ****
    \setbox\@arstrutbox=\hbox{\vrule
       height\arraystretch \ht\strutbox
       depth\arraystretch \dp\strutbox
!      width \z@}%
! %% Following lines modified by David M. Jones to fix incompatibility
! %% with M&S font selection scheme
!    \LT@cols=\z@%
!    \@mkpream{#2}%
! %  \expandafter\LT@nofcols\@preamble\@sharp\end
    \LT@test
    \edef\@preamble{\tabskip\LTleft\halign to \hsize\bgroup
      \tabskip\z@ \@arstrut \@preamble \tabskip\LTright \cr}%
--- 86,94 ----
    \setbox\@arstrutbox=\hbox{\vrule
       height\arraystretch \ht\strutbox
       depth\arraystretch \dp\strutbox
!      width \z@}\@mkpream{#2}%
!   \LT@cols=\z@
!   \expandafter\LT@nofcols\@preamble\@sharp\end
    \LT@test
    \edef\@preamble{\tabskip\LTleft\halign to \hsize\bgroup
      \tabskip\z@ \@arstrut \@preamble \tabskip\LTright \cr}%
***************
*** 172,184 ****
    \LT@get@widths
    \setbox\z@=\vbox\bgroup\@preamble}
  
! %% These macros are no longer needed.
! %% David M. Jones (6/14/91)
  
! %%  \def\LT@nofcols#1\@sharp{\futurelet\next\@LT@nofcols}
! %%  
! %%  \def\@LT@nofcols{\ifx\next\end\let\next\@gobble
! %%    \else\def\next{\advance\LT@cols\@ne\LT@nofcols}\fi\next}
  
  \def\LT@test{\expandafter\ifx\LT@save@row\relax\LT@blank@row\else
    \ifLT@save@row\LT@blank@row\fi\fi}
--- 144,153 ----
    \LT@get@widths
    \setbox\z@=\vbox\bgroup\@preamble}
  
! \def\LT@nofcols#1\@sharp{\futurelet\next\@LT@nofcols}
  
! \def\@LT@nofcols{\ifx\next\end\let\next\@gobble
!   \else\def\next{\advance\LT@cols\@ne\LT@nofcols}\fi\next}
  
  \def\LT@test{\expandafter\ifx\LT@save@row\relax\LT@blank@row\else
    \ifLT@save@row\LT@blank@row\fi\fi}

dmjones@theory.lcs.mit.edu (David M. Jones) (06/15/91)

In article <1991Jun14.212820.1290@mintaka.lcs.mit.edu>, I wrote:

>After a little thought, I decided that this was relatively painless,
>since it involves modifying only the very macro which has been causing
>us troubles, namely \@tablcassz.  

Ok, I promise this is my last posting on this topic today.  I found
one more macro that needs to be modified to make my previous scheme
work.  In addition to the changes proposed in my previous post, add
the following definition after the redefinition of \@tabclassz:

        \def\@classv{\advance\LT@cols\@ne           %% Added by dmjones
        \@addtopreamble{\@startpbox{\@nextchar}\ignorespaces
        \@sharp\@endpbox}}

------------------------------------------------------------------------------
David M. Jones                             |"Trifles! Trifles light as air!"
ARPANET: dmjones@theory.lcs.mit.edu        |            -- the Hystricide
USmail: 17 Simpson Ave.; Somerville, MA 02144
------------------------------------------------------------------------------

glenn@network.ucsd.edu (Glenn Sueyoshi) (06/15/91)

In article <1991Jun14.140857.25984@mintaka.lcs.mit.edu> dmjones@theory.lcs.mit.edu (David M. Jones) writes:

>In article <5434@network.ucsd.edu>, glenn@network (Glenn Sueyoshi) writes:

>>[stuff that I wrote about it not working]
>>I'm running LaTeX 2.09 <7 December 1989> under TeX 3.0 and have the
>>Mittelbach et al. font selection scheme installed.


>Since I haven't seen any response to this, I'll take the liberty of
>burdening the net with my analysis.
>
>The culprit is the M&S font selection scheme.  In particular,
>lfonts.new redefines \@tabclassz as follows:

[long analysis that's incomprehensible to me, but meaningful to
those more skilled at TeX than I]


Sorry to not follow up my own posting with something informative,
but I figured there was no one really cared... :)

David Jones wins the award for correctly identifying M&S as the 
culprit.  The other David (who wrote the .sty) has been in contact 
with me and has made a few changes to the .sty which seem to solve 
things.  He's also modified the \caption somewhat to more closely 
conform to LaTeX's treatment of multi-line captions.  There is
the possibility that a few other cosmetic changes may be made in 
the next week or so.  David is then planning on sending the .sty to
the relevant UK sites.  David or I can post here or send to US
sites as warranted.

Having said all that, I'd like to remove the qualification to my
support for this solution.  It's a pretty slick implementation of 
the kind of page-breaking tables that I've wanted for some time 
but did not find in the supertabular.sty and clones.  In particular, 
\longtable uses the same counters as \table so that moving from one 
to the other is pretty transparent.

My thanks to David Carlisle for his patience in dealing with me and
my unprovoked attack on his style :).  And applause to David Jones
for independently identifying the problem.  Are there any other
Davids that want to get in on this?


Glenn
gtsueyos@ucsd[.edu]

texinfo1@rusmv1.rus.uni-stuttgart.de (Rainer Schoepf) (06/18/91)

In article <1991Jun14.140857.25984@mintaka.lcs.mit.edu> dmjones@theory.lcs.mit.edu (David M. Jones) writes:
>
>I'm not sure what the correct solution is, since I don't know why the
>extra level of braces was added to \@tabclassz (I don't have a copy of
>lfonts.doc).  I don't know what would happen if we simply changed the
>definition back to the original one, but I assume something would go
>wrong somewhere.  


I can at least give some information on why this redefinition is needed
with the NFSS:

Math font changes must be done non-locally in order to work - this is due
to the way math fonts are used. Therefore, the NFSS does these changes 
globally, using \aftergroup to get control again after the current group
and restore things again globally. Without this extra set of braces the 
token inserted by \aftergroup would appear in a wrong place - it might, e.g.,
start a new row in an \halign if the font change came in the last column.



Rainer Schoepf