2

I have the problem that tables that are larger than one page are not properly split but just overlap the first page. I use tabularx with ltablex what works fine on its own but as soon as I wrap the whole thing into a threeparttable it doesn't break the page anymore. Is this combination supported? I know I could try longtable but I'd prefer to not have to have a special package depending on the size of the table.

Here's a MWE

\documentclass[a4paper,10pt,notitlepage]{article}   % papersize, fontsize, documentclass; 
\usepackage{xltabular}
\usepackage[flushleft]{threeparttablex}     % to have a dedicated notes section after tables
\usepackage[font=small, margin=0pt]{caption}            % table and figure captions
\usepackage[table]{xcolor}                  % used for table alternatively colors
\usepackage{booktabs}                       % use package booktabs for easy creating tables

% Spacing and margin rules
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{1pt}%
\setlength{\abovecaptionskip}{7pt}
\setlength{\belowcaptionskip}{10pt}
\setlength{\textfloatsep}{5pt}
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

% CAPTION STYLE
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
\DeclareCaptionFormat{labelstyle}{%
    \setlength\fboxsep{3pt}%
    \colorbox{blue}{{#1}}#2#3
} 

\captionsetup[table]{singlelinecheck=false, labelfont={color=white}}    % Rechtsbündige Tabellen und Bildbeschreibung
\captionsetup[figure]{singlelinecheck=false, labelfont={color=white}, justification = raggedright, format=labelstyle}

% ------------------------------------------------------------------------------------------------------------------------
% TABLE
\newcommand{\tablestyle} { 
    \captionsetup{type=table, format=labelstyle}
    \renewcommand{\arraystretch}{1.25}
    \arrayrulecolor{blue} 
    \aboverulesep = 0mm 
    \belowrulesep = 0mm 
    }

\newenvironment{tableenv}[2]{
    \par\vspace{0.5cm}
    \def\tablecaption{#1}
    \def\tablelabel{tab:#2}
        \small
        \tablestyle
        \begin{table}
        \begin{threeparttable}
}{
        \caption{\tablecaption}
        \label{\tablelabel}
    \end{threeparttable}
    \end{table}
}

\begin{document}

\section{Section with long table}
\begin{tableenv}{test}{test}
\begin{xltabular}{\linewidth}{@{} X @{}}

    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
    awdafgawfgawfa\\
\end{xltabular}
\end{tableenv}

\end{document}

It's still not breaking the table and I can't figure out why, it does break if I remove the tableenv environment tough.

po.pe
  • 329
  • Probably take a look at threeparttablex? – leandriis Apr 14 '20 at 09:05
  • I just found threeparttablex in combination with longtable (for multi page tables), is there a solution for using it with tabularx as well? – po.pe Apr 14 '20 at 09:10
  • I don't know since I prefer xltabular over ltablex when it comes to multiple page tables with X type columns. xltabular and threeparttablex work well together (See https://tex.stackexchange.com/a/504666/134144) – leandriis Apr 14 '20 at 09:14
  • I suggest using the xltabular package and its eponymous environment, which loads ltablex and automatically adds the \keepXColumns automatically; threeparttablex works with xltabular. – Bernard Apr 14 '20 at 09:27
  • Tried xltabular but couldn't get it working inside threeparttablex - posted a MWE – po.pe Apr 15 '20 at 07:00
  • Absolutely not threeparttable for multi-page tables! – Donald Arseneau Apr 15 '20 at 07:06
  • threeparrtablex has a different syntax than threeparttable. \begin{ThreePartTable} vs. \begin{threeparttable}. Also, you can't place a tabular that should break across pages into a table environment. – leandriis Apr 15 '20 at 07:06
  • To summarize my aboe comment, the following should work: `\newenvironment{tableenv}[2]{ \par\vspace{0.5cm} % \def\tablecaption{#1} % \def\tablelabel{tab:#2} \small \tablestyle %\begin{table} \begin{ThreePartTable} }{ % \caption{\tablecaption} % \label{\tablelabel} \end{ThreePartTable} % \end{table} }

    \begin{document}

    \section{Section with long table} \begin{tableenv}{test}{test} \begin{xltabular}{\linewidth}{@{} X @{}} \caption{my caption text here}\label{label}\ awdafgawfgawfa\ `

    – leandriis Apr 15 '20 at 07:09
  • Works like a charm, unfortunately I don't remember why I've put an additional table there in the first place, we'll see when something else stops working :) Do you wanna post an answer? – po.pe Apr 15 '20 at 07:23

0 Answers0