5

I have read the question and answers about the "-continued" heading. The code given in the answers doesn't help me. Thats why I am posting a follow-up-question here.

I want to re-display the section-titles, but I am using a longtable. (I need to write a document, which consists only of longtables. And I really need the section-titles to reappear. Using a headline does not work in my case.)

I have a longtable over (at least) two pages. And I want to re-display the current section-title. My problem is, that the longtable is continued in the same line as the re-displayed section-title. Here is the latex-code I am using:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{environ}% http://www.ctan.org/pkg/environ
\usepackage{longtable}

\makeatletter
\let\@section@title@\relax% Sectional heading storage
\patchcmd{\@sect}% <cmd>
  {\@xsect}% <search>
  {\gdef\@section@title@{% Store sectional heading
  {\noindent#6\@svsec#8\normalfont\ \smash{(continued)}}\par\bigskip}\@xsect}% <replace>
  {}{}% <success><failure>
\newif\if@sectionpage %Conditional to see if we are on the page where a section has been started
\newif\if@tab@pagebreak %Conditional to check if a table will cause a pagebreak
\newdimen\currtabheight
\newdimen\pt@saved
  \let\ltx@tabular\tabular
  \let\ltx@endtabular\endtabular
  \providecommand{\env@tabular@save@env}{}
  \providecommand{\env@tabular@process}{}
%Patching the tabular envionment
\RenewEnviron{tabular}[1]{%
  \setbox0=\hbox{% measure the height of the tabular
    \ltx@tabular{#1}
      \BODY
    \ltx@endtabular
    }
  \currtabheight=\ht0 \advance\currtabheight by \dp0%
  \pt@saved=\the\pagetotal% store the current pagetotal value
  \advance\pt@saved by \currtabheight% add the height of the current tabular
  \ifdim\pt@saved>\pagegoal% the tabular will cause a pagebreak
    \global\@tab@pagebreaktrue
  \fi
  \ltx@tabular{#1}% printing the tabular
    \BODY
  \ltx@endtabular
  }
%Doing the old shipout trick with the addtional declared conditionals
\EveryShipout{%
  \ifdim\pagetotal>\pagegoal
    \if@sectionpage
      \if@tab@pagebreak\else\aftergroup\@section@title@\fi
    \else
      \aftergroup\@section@title@
    \fi
  \fi
  \global\@sectionpagefalse
  \global\@tab@pagebreakfalse}
%redefinition to make the sectionpage-switch work
\let\ltx@section=\section
\renewcommand{\section}{\@sectionpagetrue\ltx@section}
\makeatother

\begin{document}
\section{A section}

\lipsum[1-1]

 \begin{longtable}{|l| l|}
 KILLED & LINE!!!! \kill
 \caption[An optional table caption ...]{A long table\label{long}}\\
 \hline\hline
 \multicolumn{2}{@{*}c@{*}}%
 { This part appears at the top of the table}\\ \hline
 \endfirsthead
 \multicolumn{2}{@{*}c@{*}}%
 { This part appears at the top of every other page}\\ \hline\hline
 \endhead
 \endfoot
 \endlastfoot
 columns are specified& in the \\
 same way as in the tabular& environment.\\
 Lots of lines& like this.\\
 ...   
Lots of lines& like this.\\         
 \end{longtable}

\lipsum[2-2]

\section{Second section}

\begin{tabular}{l}
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA
\end{tabular}

\lipsum[7-8]
\end{document}

As you can see, LaTeX starts the second part of the longtable in the title-continued line:

Second part of Longtable starting in same line as the re-displayed title.

Unfortunately I don't know LaTeX well enough to solve the problem. Can someone help me, please?

(I already looked at answers to these similiar questions:

Re-displaying section headings after page-breaks

How to generate a "<section> continued" heading after page-break?

Re-displaying section headings after page-breaks (with titlesec))

  • I don't get what you are trying to do with all this code. If you need something that looks like a section heading in a longtable why don't you add a line font changes ...\thesection~section (continued) before \endhead – Ulrike Fischer May 26 '14 at 16:22
  • @Ulrike, I have thought about putting the section-title in the longtable as a head. But this doesn't work here. I try to explain, what I want to do. It is a bit complicated, so I will choose a different but similiar example. Say, I want to display a lot of data about school-classes (e.g. name of teacher, number of students) for a lot of schools. (It is so much data for a class, that I must use the longtable-environment.) Since longtables cant be nested, I decided to use the section-title for the school and longtables for the school-classes. I hope, this explains what I want to do. – Anja May 27 '14 at 7:40
  • It doesn't explain why you can't put the "continued" in the next head of the longtable. (It also doesn't explain why you can't put the text in the normal header of a page). – Ulrike Fischer May 27 '14 at 7:52
  • I want to have the school and the class in the head of the table. Therefore the head changes every page or so, which is at least not easy to do with longtable. – Anja Jun 5 '14 at 12:42
1

The redefinitions in the head didn't appear to be helping, but adding \pagestyle{headings} puts the section title in the page head, even on longtable pages which seems to address the question.

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum

\usepackage{longtable}

\pagestyle{headings}

\makeatother

\begin{document}
\section{A section}

\lipsum[1-1]

 \begin{longtable}{|l| l|}
 KILLED & LINE!!!! \kill
 \caption[An optional table caption ...]{A long table\label{long}}\\
 \hline\hline
 \multicolumn{2}{@{*}c@{*}}%
 { This part appears at the top of the table}\\ \hline
 \endfirsthead
 \multicolumn{2}{@{*}c@{*}}%
 { This part appears at the top of every other page}\\ \hline\hline
 \endhead
 \endfoot
 \endlastfoot
 columns are specified& in the \\
 same way as in the tabular& environment.\\
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
 Lots of lines& like this.\\   
Lots of lines& like this.\\         
 \end{longtable}

\lipsum[2-2]

\section{Second section}

\begin{tabular}{l}
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA \\
  AAAAAAAAAAAAAAAAAAAA
\end{tabular}

\lipsum[7-8]
\end{document}
| improve this answer | |
0

I found a solution (or better work-around) in this forum to my specific problem, which is NOT an answer to my question about the "section-continued"-before-longtable-problem.

I am now putting the whole section inside a supertab-environment and change the running-head. How to do this is explained here:

Change running heads in longtable (or other "long table" package)

I am still interested in an answer to my actual question, because placing several longtables in a section seems cleaner than placing everything in a long table with the supertab-package.

I want to thank @Ulrike Fischer. Her comment made me look at this approach to my problem again.

(I am posting this as an answer, because this seems better than using the comment-function. If it isn't please tell me and I will remove this post.)

| improve this answer | |
  • a self-answer is fine, but I still don't understand the problem, section headings should go in the page head (which is the default behaviour) the table heading is within the page body – David Carlisle Sep 23 '14 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.