3

Here's a (minimal?) working example that illustrates both the issues I am having:

\documentclass{article}
\usepackage{longtable,booktabs,lipsum,array}
\usepackage{pgfplots}
\newcommand{\sheaf}{\mathcal}
\begin{document}
\begin{longtable}{>{\raggedright}m{2.5in} c c c c c c c}
\caption{Degree 8 curves\label{table:degree_8}}\\ \toprule 
Rational curve: \\$[t,s] \mapsto$ & $\sheaf E_{1} |_C$ & $\sheaf E_{2} |_C$ & $\sheaf E_{3} |_C$ & $\sheaf E_{4} |_C$ & $\sheaf E_{5} |_C$ & $\sheaf E_{6} |_C$\\ \midrule 
\endfirsthead
\caption[]{Degree 8 curves (continued)}\\ \toprule 
Rational curve: \\$[t,s] \mapsto$ & $\sheaf E_{1} |_C$ & $\sheaf E_{2} |_C$ & $\sheaf E_{3} |_C$ & $\sheaf E_{4} |_C$ & $\sheaf E_{5} |_C$ & $\sheaf E_{6} |_C$\\ \midrule 
\multicolumn{1}{c}{\vdots} & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \cmidrule{2-7} 
\endhead
\multicolumn{1}{c}{\vdots} & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots\\ \bottomrule
\endfoot
\endlastfoot
\pgfplotsforeachungrouped \i in {0,...,22}
{
    \lipsum[\i] & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ \\
    \cmidrule{2-7}
}
\lipsum[1] & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ \\ \bottomrule
\end{longtable}
\end{document}

I'm not even going to try to post a picture, but here are the issues:

  1. On the first page (and almost every page thereafter), the \cmidrule comes right before the footer. I would prefer for the \cmidrule here to be eliminated altogether. Is there any way to manage this?
  2. The \cmidrule at the end of page 13 has been pushed onto page 14, producing an obviously unwanted effect. Assuming my first request is not feasible, is there a way to correct this (that does not involve manual adjustments to the page breaking, which kind of defeats the whole purpose of using longtable)?
  • Note that question 2 is very similar to the question linked below, but that question does not seem to address question 1 at all (so far as I can tell), and in any case it is still not clear to me how the answers there would apply to the given MWE. tex.stackexchange.com/q/42412/484 – Charles Staats Apr 24 '13 at 20:26
5

this removes \cmidrule at a page break.

\documentclass{article}
\usepackage{longtable,booktabs,lipsum,array}
\usepackage{pgfplots}
\newcommand{\sheaf}{\mathcal}
\makeatletter

\def\LT@output{%
  \ifnum\outputpenalty <-\@Mi
    \ifnum\outputpenalty > -\LT@end@pen
      \LT@err{floats and marginpars not allowed in a longtable}\@ehc
    \else
      \setbox\z@\vbox{\unvbox\@cclv}%
      \ifdim \ht\LT@lastfoot>\ht\LT@foot
        \dimen@\pagegoal
        \advance\dimen@-\ht\LT@lastfoot
        \ifdim\dimen@<\ht\z@
          \setbox\@cclv\vbox{\unvbox\z@
\copy\LT@foot\vss}%
          \@makecol
          \@outputpage
          \setbox\z@\vbox{\box\LT@head}%
        \fi
      \fi
      \global\@colroom\@colht
      \global\vsize\@colht
      \vbox
        {\unvbox\z@
\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}%
    \fi
  \else
    \setbox\@cclv\vbox{\unvbox\@cclv
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setbox0\lastbox
\ifdim\ht0=0.29999pt \unskip % hope that was a cline we threw away
\else
\nointerlineskip
\box0     % put it back, whatever it was
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\copy\LT@foot\vss}%
    \@makecol
    \@outputpage
      \global\vsize\@colroom
    \copy\LT@head\nobreak
  \fi}


\makeatother

\begin{document}
\LTleft-20pt 
\LTright-20pt plus \fill
\begin{longtable}{>{\raggedright}m{2.5in} c c c c c c c}
\caption{Degree 8 curves\label{table:degree_8}}\\ \toprule 
Rational curve: \\$[t,s] \mapsto$ & $\sheaf E_{1} |_C$ & $\sheaf E_{2} |_C$ & $\sheaf E_{3} |_C$ & $\sheaf E_{4} |_C$ & $\sheaf E_{5} |_C$ & $\sheaf E_{6} |_C$\\ \midrule 
\endfirsthead
\caption[]{Degree 8 curves (continued)}\\ \toprule 
Rational curve: \\$[t,s] \mapsto$ & $\sheaf E_{1} |_C$ & $\sheaf E_{2} |_C$ & $\sheaf E_{3} |_C$ & $\sheaf E_{4} |_C$ & $\sheaf E_{5} |_C$ & $\sheaf E_{6} |_C$\\ \midrule 
\multicolumn{1}{c}{\vdots} & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\ \cmidrule{2-7} 
\endhead
\multicolumn{1}{c}{\vdots} & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots\\ \bottomrule
\endfoot
\endlastfoot
\pgfplotsforeachungrouped \i in {0,...,22}
{
    \lipsum[\i] & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ \\
    \cmidrule{2-7}
}
\lipsum[1] & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ & $\Sigma$ \\ \bottomrule
\end{longtable}
\end{document}
  • There's nothing like having the package author around to ensure good answers! When I tried this out, it worked on all the page-end \cmidrules except the one that got pushed to the top of the last page (resulting in a doubled line there). However, when I then eliminated the \cmidrules in the header, this fixed itself, leaving no \cmidrules at the top of the last page. Is this behavior consistent, or just a quirk of this particular example? (E.g., perhaps eliminating the line at the top of page 13 removed just enough space that the end-of-page line wasn't pushed to the next page.) – Charles Staats Apr 24 '13 at 21:34
  • One other question: Is this solution at all robust under possible future modifications to the longtable package? – Charles Staats Apr 24 '13 at 21:34
  • @CharlesStaats Not necessarily but it's not the first time this has come up so it's possible that any future updates will take account of it, and anyway longtable updates once or twice a decade so it's not an immediate concern:-) – David Carlisle Apr 24 '13 at 21:43
  • 1
    @CharlesStaats If it's a concern you could use \CheckCommand to check the definition of \LT@Output before redefining it then if it does ever change you get an explicit error rather than it may or may not working due to unknown factors – David Carlisle Apr 24 '13 at 21:45

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.