4

I am trying to use a tabular environment that has the features of tabulary but allows for multiple page tables (this 'catch-all' solution is necessary as by latex code automatically generated so a single "table environment" combining the features of these packages is ideal).

At present the table numberings are incorrect - each table increments the numbering by two, so the e.g. the first two tables are numbered 0.1 and 0.3 (not 0.2!).

I've tried to provide a minimal example below, which demonstrates the column width adjustment (in table 1) and multi page feature (in table 2), whilst showing the numbering issue. This is about as minimal a reproducible example as I can make.

For reference, the ltabulary environment was taken from the following sources:

Code:

\documentclass[oneside]{scrbook}

\usepackage{longtable}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage[referable]{threeparttablex}
\usepackage{caption}

% define ltabulary environment
\makeatletter
\newcommand*\TY@cap@gobble[2][]{\\}% from ltxtable (adjusted)
\def\ltabulary{%
    \def\caption{% from ltxtable (adjusted)
        \@ifstar\TY@cap@gobble\TY@cap@gobble}
    \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

\begin{document}

\mainmatter

    \begin{ThreePartTable}
    \captionof{table}{Short table (with long columns)}
    \begin{ltabulary}{L L L L }
        \toprule
        H1 & H2 & H3 & H4\\
        \midrule
        \endfirsthead
        \toprule
        H1 & H2 & H3 & H4\\
        \midrule
        \endhead
        \endfoot
        \bottomrule
        \endlastfoot
        A & B & C & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu lorem et massa interdum commodo a et nisi. Suspendisse mauris velit, molestie et iaculis at, posuere vel dui. Aenean at ante lorem. Nullam porttitor vestibulum scelerisque. Maecenas et posuere nisi\\
    \end{ltabulary}
    \label{comparisons_table}
    \end{ThreePartTable}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu lorem et massa interdum commodo a et nisi. Suspendisse mauris velit, molestie et iaculis at, posuere vel dui. Aenean at ante lorem. Nullam porttitor vestibulum scelerisque. Maecenas et posuere nisi, id finibus metus. Vivamus vehicula viverra vestibulum. Morbi sed tellus at mi mollis rutrum quis ut est. Vivamus consequat consectetur purus, id pellentesque elit pretium et. Fusce luctus, nibh sit amet mollis volutpat, ex enim pretium ipsum, at pharetra justo erat ut dui. Interdum et malesuada fames ac ante ipsum primis in faucibus.


    \begin{ThreePartTable}
    \captionof{table}{Long table}
    \begin{ltabulary}{L L L L }
        \toprule
        H1 & H2 & H3 & H4\\
        \midrule
        \endfirsthead
        \toprule
        H1 & H2 & H3 & H4\\
        \midrule
        \endhead
        \endfoot
        \bottomrule
        \endlastfoot
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
    \end{ltabulary}
    \label{comparisons_table}
    \end{ThreePartTable}

\end{document}

Output (page 1): Page 1 Output

1
  • Just use longtable's method for producing the captions and it will work fine.
    – cfr
    Oct 8, 2015 at 23:52

1 Answer 1

3

Just use longtable's method for handling the captions and it will work fine:

the tabulars came in one-by-one...

\documentclass[oneside]{scrbook}

\usepackage{longtable}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage[referable]{threeparttablex}
\usepackage{caption}

% define ltabulary environment
\makeatletter
\newcommand*\TY@cap@gobble[2][]{\\}% from ltxtable (adjusted)
\def\ltabulary{%
    \def\caption{% from ltxtable (adjusted)
        \@ifstar\TY@cap@gobble\TY@cap@gobble}
    \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

\begin{document}

\mainmatter

\begin{ThreePartTable}
  \begin{ltabulary}{L L L L }
  \caption{Short table (with long columns)\label{comparisons_table}}\\
    \toprule
    H1 & H2 & H3 & H4\\
    \midrule
    \endfirsthead
    \toprule
    H1 & H2 & H3 & H4\\
    \midrule
    \endhead
    \endfoot
    \bottomrule
    \endlastfoot
    A & B & C & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu lorem et massa interdum commodo a et nisi. Suspendisse mauris velit, molestie et iaculis at, posuere vel dui. Aenean at ante lorem. Nullam porttitor vestibulum scelerisque. Maecenas et posuere nisi\\
  \end{ltabulary}
\end{ThreePartTable}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu lorem et massa interdum commodo a et nisi. Suspendisse mauris velit, molestie et iaculis at, posuere vel dui. Aenean at ante lorem. Nullam porttitor vestibulum scelerisque. Maecenas et posuere nisi, id finibus metus. Vivamus vehicula viverra vestibulum. Morbi sed tellus at mi mollis rutrum quis ut est. Vivamus consequat consectetur purus, id pellentesque elit pretium et. Fusce luctus, nibh sit amet mollis volutpat, ex enim pretium ipsum, at pharetra justo erat ut dui. Interdum et malesuada fames ac ante ipsum primis in faucibus.


\begin{ThreePartTable}
  \begin{ltabulary}{L L L L }
    \caption{Long table\label{comparisons_table}}\\
    \toprule
    H1 & H2 & H3 & H4\\
    \midrule
    \endfirsthead
    \toprule
    H1 & H2 & H3 & H4\\
    \midrule
    \endhead
    \endfoot
    \bottomrule
    \endlastfoot
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
  \end{ltabulary}

\end{ThreePartTable}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .