I'm trying to typeset some multipage tables with tablenotes and repeating captions on each page. I found this question, which marries the longtable
environment with tabulary
. This is quite nice, because then I don't need to take care of the column widths myself, but can use one of the LRJC
options of tabulary
to do that for me.
In the following MWE, almost everything works out nicely, but there are some caption problems.
\documentclass{scrartcl}
\usepackage[hypcap=true]{caption}
\captionsetup{labelfont=bf, justification=justified, singlelinecheck=false, format=plain}
\usepackage{tabulary, booktabs, longtable, ltcaption}
\usepackage[referable]{threeparttablex}
%% define a new envrionment which marries longtable with tabulary
\makeatletter
\def\ltabulary{%
\def\endfirsthead{\\}%
\def\endhead{\\}%
\def\endfoot{\\}%
\def\endlastfoot{\\}%
\def\tabulary{%
\def\TY@final{%
\def\endfirsthead{\LT@end@hd@ft\LT@firsthead}%
\def\endhead{\LT@end@hd@ft\LT@head}%
\def\endfoot{\LT@end@hd@ft\LT@foot}%
\def\endlastfoot{\LT@end@hd@ft\LT@lastfoot}%
\longtable}%
\let\endTY@final\endlongtable
\TY@tabular}%
\dimen@\columnwidth
\advance\dimen@-\LTleft
\advance\dimen@-\LTright
\tabulary\dimen@}
\def\endltabulary{\endtabulary}
\makeatother
% from https://tex.stackexchange.com/questions/78075/multi-page-with-tabulary (see there for usage)
\begin{document}
\begin{table}
\caption{Nice long caption directly above the start of the table with lots of...}
\begin{threeparttable}
\begin{tabulary}{\textwidth}{LlLLL}
\toprule
top cell one with title & top cell two with title & longtop with note & top cell four with title & top cell five with title\\
\midrule
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
\bottomrule
\end{tabulary}
\begin{tablenotes}\footnotesize
\note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
\end{tablenotes}
\end{threeparttable}
\end{table}
\begin{ThreePartTable}
\begin{TableNotes}\footnotesize
\note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
\end{TableNotes}
% \setlength\LTleft{0pt}
% \setlength\LTright{0pt}
\captionof{table}{Example of long table over multiple pages}
\begin{ltabulary}{rLlcccc}
\toprule
cell 1 & cell with linebreaks if it gets too wide and wider and wider and wider and wider & cell 3 & cell 4 & 5 & 6 & 7 \\
\midrule
\endfirsthead
\toprule
cell 1 & cell with linebreaks if it gets too wide & cell 3 & cell 4 & 5 & 6 & 7 \\
\midrule
\endhead
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
1 & 2 & 3 & 4 & 5 & 6 & 7 \\
\end{ltabulary}
\end{ThreePartTable}
\begin{table}
\caption{Nice long caption directly above the start of the table with lots of...}
\begin{threeparttable}
\begin{tabulary}{\textwidth}{LlLLL}
\toprule
top cell one with title & top cell two with title & longtop with note & top cell four with title & top cell five with title\\
\midrule
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
cell & cell & big long cell stuff & cell & more cell\\
\bottomrule
\end{tabulary}
\begin{tablenotes}\footnotesize
\note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
The above code compiles fine, but I have to use \captionof
which produce problems 2 to 4. If I replace it with \caption{Example of long table over multiple pages}
, I get the errors in problem 1.
These are the problems:
- I cannot use the
\caption{}
command. It gives me! LaTeX Error: \caption outside float
. This is the case regardless if I use thecaption
package or not. Also, the placement does not matter. I can put it inside theltabulary
environment or outside, both times it gives me the same error. I suspect that, sincelongtable
uses its own caption command and it's not included in the definition ofltabulary
from the question, it does not work. If that is the case, the error makes sense, becauselongtable
is not set inside a float which\caption
needs. I worked around this by using the\captionof
command from thecaption
package, but this comes with its own problems: - The spacing between the caption and the table is too big compared to the other two tables. This can be fixed with
\vspace{-12pt}
, but it's rather tedious to do that for each table. - The numbering of subsequent tables is wrong. The third table in the MWE is numbered 4 instead of 3. I suspect this is a problem with longtable and
\captionof
, because longtable sets a new table for each page which increases the table counter. This can be fixed with\addtocounter{table}{-1}
, but this is, again, rather tedious. - I cannot repeat the caption for each page, because
\captionof
inside theltabulary
environment gives me an error:! Missing \endgroup inserted
. I could probably fix this by setting the caption manually, but this is even more tedious, because if I move a table, I have to go back to each table and adjust the numbering. It should also not repeat the whole caption for each page, but add something along the lines of "Table 2 (continued)".
Is there some wizard here who can add the \caption
command to the ltabulary
definition (which would presumably fix all the problems above in one go), or fix it some other way?