Discussion:
Spurious extra heading with longtable
(too old to reply)
douglasr
2008-03-16 08:13:56 UTC
Permalink
I often experience the problem of spurious extra headings being
generated by longtable.

For example, the following:

% --------------------------------------
Some text of variable length before the longtable ...
\begin{longtable}{ll}
Heading
\endfirsthead
Heading (continued)
\endhead
a & b\\
c & d\\
e & f
\end{longtable}
More text after the longtable ...
% --------------------------------------

can sometimes produce:
Some text of variable length before the longtable ...
Heading
a b
c d
e f

<at top of the following page>
Heading (continued)
More text after the longtable ...

i.e., a spurious heading can appear at the top of a page with no
subsequent rows of the longtable (all the rows having been already
properly generated on the previous page).

The problem likely only occurs with particular height of the page
content before the longtable. A small change of vertical spacing can
either trigger or suppress a spurious extra heading.

Since my longtables are usually generated programatically from a
database, it is troublesome to check for and suppress such spurious
headings.

Any ideas for a solution would be much appreciated.

Best Regards,
Douglas
vvvv
2008-03-16 23:11:28 UTC
Permalink
You might have to post a specific example so we can see what is
happening -- and I suppose it is really long. I think the interface
here will allow long posts, but it might get confused if the lines are
long (due to word wrapping).

My first thought was maybe the sum of the line heights are not evenly
divisible into the page height. In other words, see if the page
height is an EXACT multiple of the \baselineskip (or maybe
\baselineskip plus \tabrowsep or \extrarowheight if you added
something like that), but I don't think that should cause the extra
header.
Ulrike Fischer
2008-03-17 08:36:19 UTC
Permalink
Post by vvvv
You might have to post a specific example so we can see what is
happening -- and I suppose it is really long. I think the interface
here will allow long posts, but it might get confused if the lines are
long (due to word wrapping).
Such examples can be shorten by using spaces between the lines: \\[15cm]

And text before the table can be inserted with the lipsum package.
--
Ulrike Fischer
Ulrike Fischer
2008-03-17 08:44:03 UTC
Permalink
Post by douglasr
I often experience the problem of spurious extra headings being
generated by longtable.
% --------------------------------------
Some text of variable length before the longtable ...
\begin{longtable}{ll}
Heading
\endfirsthead
Heading (continued)
\endhead
a & b\\
c & d\\
e & f
\end{longtable}
More text after the longtable ...
% --------------------------------------
...
Post by douglasr
<at top of the following page>
Heading (continued)
More text after the longtable ...
Since my longtables are usually generated programatically from a
database,
In your example the last line of the tabular has no \\ command. But is
this true also for the generated longtables?
--
Ulrike Fischer
douglasr
2008-03-17 13:46:48 UTC
Permalink
Post by Ulrike Fischer
Post by douglasr
I often experience the problem of spurious extra headings being
generated by longtable.
% --------------------------------------
Some text of variable length before the longtable ...
\begin{longtable}{ll}
Heading
\endfirsthead
Heading (continued)
\endhead
a & b\\
c & d\\
e & f
\end{longtable}
More text after the longtable ...
% --------------------------------------
...
Post by douglasr
<at top of the following page>
Heading (continued)
More text after the longtable ...
Since my longtables are usually generated programatically from a
database,
In your example the last line of the tabular has no \\ command. But is
this true also for the generated longtables?
--
Ulrike Fischer- Hide quoted text -
- Show quoted text -
I don't usually bother whether the last line has a \\ or not. My
experience has been that the same spacing results at the end of
tabulars or longtables whether or not this is present. However, this
is something I can check - possibly the spurious longtable headings
are related to this.

The longtable file relating to the latest observed occurrence of a
spurious heading does have the extra \\ at the end - actually, to be
more precise a \tabularnewline

I made a lot of changes over the weekend - text content, spacing of
headings above, etc. and there is no spurious heading seen at present,
even although the surplus \tabularnewline is still present.

I don't have a working example of the problem at present. I have
observed such spurious headings from time to time over a long period.
Generally they disappear when I make other changes to the text content
or spacing. When I next see the effect, I shall try to capture the
details so that there is a well defined file for reference. I shall
also try with and without the surplus \tabularnewline to check if it
is an issue.

I think the problem is subtly related to spacing of the text preceding
the longtable so it may be difficult to provide a simple example
including all the rubber spacing, etc. that is generally present.

There have been no follow-ups to my other posting of 16th March
entitled: Section headings and longtables

This is actually quite an interesting and useful topic. It is
generally useful to have a section heading above a longtable that is
guaranteed to remain on the same page as the beginning of the table
but longtable lacks this feature. The work-around idea of
incorporating the section heading within the longtable is good if the
spacing issues can be resolved.

The two subjects may well be related in that there is a common theme
of spacing issues before the heading.

Best Regards,
Douglas
Ulrike Fischer
2008-03-17 14:33:39 UTC
Permalink
Post by douglasr
Post by Ulrike Fischer
In your example the last line of the tabular has no \\ command. But is
this true also for the generated longtables?
I don't usually bother whether the last line has a \\ or not. My
experience has been that the same spacing results at the end of
tabulars or longtables whether or not this is present. However, this
is something I can check - possibly the spurious longtable headings
are related to this.
\\ at the end of the tabular bear the danger that code after the line --
even if doesn't print -- leads to an invisible line or to a lonely
heading:

\documentclass{article}
\begin{document}
\begin{tabular}{|l}
a\\
\end{tabular}
\quad
\begin{tabular}{|l}
a\\\relax
\end{tabular}
\end{document}

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{array,longtable}
\textheight10\baselineskip
\begin{document}
some text

\begin{longtable}{l}
Heading
\endfirsthead
Heading (continued)
\endhead
text\\text\\text\\text\\text\\text\\
text\\\relax
\end{longtable}

some text
\end{document}
--
Ulrike Fischer
douglasr
2008-03-17 17:32:23 UTC
Permalink
Post by Ulrike Fischer
Post by Ulrike Fischer
In your example the last line of the tabular has no \\ command. But is
this true also for the generated longtables?
I don't usually bother whether the last line has a \\ or not.  My
experience has been that the same spacing results at the end of
tabulars or longtables whether or not this is present.  However, this
is something I can check - possibly the spurious longtable headings
are related to this.
\\ at the end of the tabular bear the danger that code after the line --
even if doesn't print -- leads to an invisible line or to a lonely
\documentclass{article}
\begin{document}
\begin{tabular}{|l}
a\\
\end{tabular}
\quad
\begin{tabular}{|l}
a\\\relax
\end{tabular}
\end{document}
\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{array,longtable}
\textheight10\baselineskip
\begin{document}
some text
\begin{longtable}{l}
Heading
\endfirsthead
Heading (continued)
\endhead
text\\text\\text\\text\\text\\text\\
text\\\relax
\end{longtable}
some text
\end{document}
--
Ulrike Fischer
That is a convincing demonstration to confirm the importance of not
terminating the last row with a \\

I do not understand why you have included \relax in the examples and
should appreciate if you could clarify that aspect.

When I generate the longtable from a database, my code is like the
following:

...
BEGIN
Fetch NextRow
WHILE
Generate the row\\
REPEAT
EndLongtable

Recently, I have not been bothering to suppress the last \\ since it
is a little troublesome to check for the end of the recordset and
conditionally add the \\

I can do the following:
BEGIN
Fetch NextRow
WHILE
Generate the row
LastRow? NOT
IF
\\
THEN
REPEAT
EndLongtable

I am wondering if there is any way to counteract a \\ If so, my code
could be like the following:
BEGIN
Fetch NextRow
WHILE
Generate the row\\
REPEAT
DeleteLast\\
EndLongtable

Is there any TeX/ LaTeX code that can perform the action of my psuedo-
code DeleteLast\\

Many thanks for your help.

Douglas
Ulrike Fischer
2008-03-17 17:46:36 UTC
Permalink
Post by douglasr
Post by Ulrike Fischer
\\ at the end of the tabular bear the danger that code after the line --
even if doesn't print -- leads to an invisible line or to a lonely
That is a convincing demonstration to confirm the importance of not
terminating the last row with a \\
I do not understand why you have included \relax in the examples and
should appreciate if you could clarify that aspect.
Because it is the command that triggers the building of the next line.
Without it there is normally no problem. But is quite possible that the
\end{longtable} contains some code that has sometimes a similar effect
than the \relax in my example.
--
Ulrike Fischer
Nicola Talbot
2008-03-18 10:57:14 UTC
Permalink
Post by Ulrike Fischer
Because it is the command that triggers the building of the next line.
Without it there is normally no problem. But is quite possible that the
\end{longtable} contains some code that has sometimes a similar effect
than the \relax in my example.
That will explain the glossaries bug mentioned in <http://
groups.google.com/group/comp.text.tex/tree/browse_frm/thread/
ee5e7857dcc9dbd8/47df96fd71a82341?hl=en&rnum=1&_done=%2Fgroup
%2Fcomp.text.tex%2Fbrowse_frm%2Fthread%2Fee5e7857dcc9dbd8%3Fhl%3Den
%26#doc_0da5da94318c0cd7>

(Header can appear on new page, even when no entries will follow)
since each glossary entry (including the last) is followed by \\
Note sure of the best way of fixing that at present.

Regards
Nicola Talbot
Robin Fairbairns
2008-03-18 11:26:04 UTC
Permalink
Post by Nicola Talbot
(Header can appear on new page, even when no entries will follow)
since each glossary entry (including the last) is followed by \\
Note sure of the best way of fixing that at present.
start each line of output, except the first, with \\

(needs an \***@firstglossaryline, but resetting that isn't so bad.)
--
Robin Fairbairns, Cambridge
Ulrike Fischer
2008-03-18 11:30:07 UTC
Permalink
Post by Nicola Talbot
Post by Ulrike Fischer
Because it is the command that triggers the building of the next line.
Without it there is normally no problem. But is quite possible that the
\end{longtable} contains some code that has sometimes a similar effect
than the \relax in my example.
That will explain the glossaries bug mentioned in <http://
groups.google.com/group/comp.text.tex/tree/browse_frm/thread/
ee5e7857dcc9dbd8/47df96fd71a82341?hl=en&rnum=1&_done=%2Fgroup
%2Fcomp.text.tex%2Fbrowse_frm%2Fthread%2Fee5e7857dcc9dbd8%3Fhl%3Den
%26#doc_0da5da94318c0cd7>
(Header can appear on new page, even when no entries will follow)
since each glossary entry (including the last) is followed by \\
Note sure of the best way of fixing that at present.
Do you have a minimal example that shows the problem? Until now it is
only a hypothese that the \\ is responsable.

With an example you then try with something like this if the problem
disappear if you move the \\ at the start of the entries:

\documentclass{article}
\usepackage{array}


\begin{document}

\let\mynewline\relax
x\begin{tabular}[t]{c}
\mynewline\global\let\mynewline\tabularnewline a
\mynewline\global\let\mynewline\tabularnewline a
\mynewline\global\let\mynewline\tabularnewline a
\mynewline\global\let\mynewline\tabularnewline a
\end{tabular}

\end{document}
--
Ulrike Fischer
Nicola Talbot
2008-03-18 12:08:01 UTC
Permalink
Post by Ulrike Fischer
Do you have a minimal example that shows the problem? Until now it is
only a hypothese that the \\ is responsable.
Curiously, it only seems to happen when using supertabular rather than
longtable. Minimal example:

\documentclass{article}

\usepackage[style=superheader]{glossaries}
\makeglossaries

\renewcommand{\glossarysection}[2][]{}

\newglossaryentry{sample1}{name={Sample 1},
description={Description 1}}

\newglossaryentry{sample2}{name={Sample 2},
description={Description 2}}

\begin{document}
\glsaddall\mbox{}\vspace{\textheight}\vspace{-5\baselineskip}

\printglossaries
\end{document}

latex test
makeglossaries test
latex test

yields a header at the top of page 2, but changing the package option
to style=longheader works fine.

The above example is equivalent to:

\documentclass{article}

\usepackage{supertabular}

\begin{document}
\mbox{}\vspace{\textheight}\vspace{-5\baselineskip}

\tablehead{\bfseries Notation & \bfseries Description\\}%
\tabletail{}%
\begin{supertabular}{ll}
Sample 1 & Description 1\\
Sample 2 & Description 2\\
\end{supertabular}
\end{document}

Removing the final \\ results in a "Misplaced \noalign" error, so it
looks like there's no point in me changing the glossaries package to
remove the final \\.

Regards
Nicola Talbot
Ulrike Fischer
2008-03-18 13:01:23 UTC
Permalink
Post by Nicola Talbot
Post by Ulrike Fischer
Do you have a minimal example that shows the problem? Until now it is
only a hypothese that the \\ is responsable.
Curiously, it only seems to happen when using supertabular rather than
longtable.
That's an known problem of supertabular. It's even mentioned in the
documentation.
Post by Nicola Talbot
Removing the final \\ results in a "Misplaced \noalign" error, so it
looks like there's no point in me changing the glossaries package to
remove the final \\.
If the \\ leads to a problem with longtable and you want to remove it,
you can get around the problem with supertabular by putting the \\ in
the tails:

\documentclass{article}

\usepackage{supertabular}

\begin{document}
\mbox{}\vspace{\textheight}\vspace{-6\baselineskip}

\tablehead{\bfseries Notation & \bfseries Description\\}%
\tabletail{\\}%
\tablelasttail{\\}
\begin{supertabular}{ll}
Sample 1 & Description 1\\
Sample 2 & Description 2
\end{supertabular}
\end{document}
--
Ulrike Fischer
Nicola Talbot
2008-03-18 13:27:35 UTC
Permalink
Post by Ulrike Fischer
That's an known problem of supertabular. It's even mentioned in the
documentation.
Oops --- haven't read it for a long time. (I don't usually use
supertabular: I copied the relevant code over from the glossary
package which I wrote years ago.)
Post by Ulrike Fischer
If the \\ leads to a problem with longtable and you want to remove it,
you can get around the problem with supertabular by putting the \\ in
Thanks for that and thanks to Robin for his suggestion as well. As I
haven't been able to generate a minimal example that causes the
problem using longtable, I think I'll refrain from meddling for now
--- it seems that every time I fix something, something else
breaks ;-)

Regards
Nicola Talbot

Loading...