1

The standard use case for longtable must be as follows:

  • Headers on every page
  • Caption on the first page
  • Table x: Continued... on each subsequent page

So why does this seem so hard to do? This SE answer suggests that the right way to do this is:

\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\begin{longtable}{ll}
\caption{My favourite caption}\label{tbl:table}\\
    \toprule
                  & foo \\
    \midrule
    \endfirsthead
\caption{Continued...}\\
    \toprule
                  & foo \\
    \midrule
    \endhead
    bar           & 1 \\
    baz           & 2 \\
    \bottomrule
\end{longtable}
\end{document}

But this seems to me to be a seriously flawed workflow. If I notice a typo in the column headers (and there may be many column headers!) I have to fix it in two different places!

Is there really no way to achieve what seems to me to be the completely standard use case without breaking this pretty fundamental rule of coding?

2

1 Answer 1

3

You do have a macro processor to hand....

\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\newcommand\foo{%
    \toprule
                  & foo \\
    \midrule}
\begin{longtable}{ll}
\caption{My favourite caption}\label{tbl:table}\\
\foo
    \endfirsthead
\caption{Continued...}\\
\foo
    \endhead
    bar           & 1 \\
    baz           & 2 \\
    \bottomrule
\end{longtable}
\end{document}
5
  • 1
    This is a sensible way to go. But I think the world is divided into those who use \newcommand pretty much constantly, and those (like me, sadly) who are too scared to even get started with it. I always think that if a package requires \newcommand to work as expected, the package needs an overhaul.
    – LondonRob
    Oct 10, 2014 at 15:22
  • 2
    @LondonRob it's not that the package requires it, it's an author command, If you need to type any set of words or commands more than once you are free to make a macro so you only need it once. That's nothing to do with longtable, same applies to subterms of equations, common technical phrases in your subject area, anything really. Oct 10, 2014 at 15:33
  • True, @DavidCarlisle, but I suppose that my objection is to the extremely common nature of the use case. Basically everyone who uses longtable will want to do some variant on this, so it should be baked in.
    – LondonRob
    Oct 10, 2014 at 16:21
  • 3
    @LondonRob I disagree (and it's my code so I win:-) It would mean implementing and documenting some kind of macro replacement system specific for this case in the general macro language of tex which seems odd. You can't just say "duplicate the header" as the non duplicated parts (the caption, the label, the continued....) might appear at the top or botom or middle of the header code so you'd have to implement and document positional options which is more complicated to implement and more complicated for the user who may be expected to be familiar with \newcommand Oct 10, 2014 at 16:31
  • Wow! Didn't know I was talking to the developer! Maybe just some documentation that makes this use case as clear as day. Keep up the good work.
    – LondonRob
    Oct 11, 2014 at 13:56

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.