Format table notes with longtable + threeparttablex

longtablethreeparttablethreeparttablex

With threeparttable and the regular tabular environment I was able to achieve the formatting of a custom note (flush left, spanning the entire width of the table, no label, while keeping the table footnotes indented) by adding it outside of the tablenotes environment (but within the threeparttable environment, see code below and table 1 in the screenshot).

Now I am trying to replicate this formatting with the combination threeparttablex + longtable but I am struggling to achieve the same effect. The only viable option so far seems to be adding it below insertTableNotes. But then the custom note would be treated as a normal row that increases the table width instead of being wrapped:

enter image description here

Does anyone have a solution for replicating the formatting from table 1 without manually specifying the table width?

Note: The reasons why I am not using the \note command or the flushleft option from threeparttablex are that 1) I would like to be able to pass a note without label and 2) flushleft doesn't perfectly left-align the text.

\documentclass{article}

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

\begin{document}

\begin{center}
  \begin{threeparttable}
  \caption{tabular}
    \begin{tabular}{l c c c c c }
      \toprule
        type & cyl & disp & hp & drat & mpg\\
      \midrule
        Ferrari & 6 & 160 & 110 & 3.9  & 3.2\\
        VW & 6 & 160 & 110 & 3.9 & 3.7 \\
        Chevrolet & 4\tnote{a} & 108 & 93 & 3.85 & 3.5\\
        Tesla & 6 & 258 & 110 & 3.08 \\
        Ford & 8 & 360 & 175\tnote{b} & 3.15 & 32.6 \\
      \bottomrule
    \end{tabular}\footnotesize
    \begin{tablenotes}\footnotesize
        \item [a] A note that might as well span multiple rows despite being a footnote.
        \item [b] Another short note.
    \end{tablenotes}
    Here is some other stuff outside the tablenotes environment that might span multiple lines.
  \end{threeparttable}
\end{center}

\begin{ThreePartTable}
\begin{TableNotes}\footnotesize
    \item [a] A note that might as well span multiple rows despite being a footnote.
    \item [b] Another short note.
\end{TableNotes}
\begin{longtable}{l c c c c c }
\caption{longtable}\\
  \toprule
    type & cyl & disp & hp & drat & mpg\\
  \midrule
    Ferrari & 6 & 160 & 110 & 3.9  & 3.2\\
    VW & 6 & 160 & 110 & 3.9 & 3.7 \\
    Chevrolet & 4\tnote{a} & 108 & 93 & 3.85 & 3.5\\
    Tesla & 6 & 258 & 110 & 3.08 \\
    Ford & 8 & 360 & 175\tnote{b} & 3.15 & 32.6 \\
    \bottomrule
  \insertTableNotes\\
  \footnotesize
  Here is some other stuff... but it will be treated as a normal row and not be confined to the table width.
\end{longtable}
\end{ThreePartTable}

\end{document}

Best Answer

Here is a solution using the tabularray package.

\documentclass{article}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\NewTblrTheme{MyTheme}{
    \DefTblrTemplate{remark}{MyTmp}{
        \DefTblrTemplate{remark-tag}{MyTag}{}
        \DefTblrTemplate{remark-sep}{MyTag}{}
        \DefTblrTemplate{remark-text}{MyTag}{\InsertTblrRemarkText}
        \MapTblrRemarks{%
        \noindent
        \UseTblrTemplate{remark-tag}{MyTag}%
        \UseTblrTemplate{remark-sep}{MyTag}%
        \UseTblrTemplate{remark-text}{MyTag}
        \par
        }
    }

    \SetTblrTemplate{remark}{MyTmp}
}

\begin{document}
\begin{longtblr}[
    theme = MyTheme,
    caption = {longtable},
    label = {tab:long},
    note{a} = {A note that might as well span multiple rows despite being a footnote.},
    note{b} = {Another short note.},
    remark{} = {Here is some other stuff... but it will be treated as a normal row and not be confined to the table width.},
]{%
    colspec = {lccccc},
    rowhead = 2,
}
    \toprule
    type & cyl & disp & hp & drat & mpg\\
    \midrule
    Ferrari & 6 & 160 & 110 & 3.9  & 3.2\\
    VW & 6 & 160 & 110 & 3.9 & 3.7 \\
    Chevrolet & 4\TblrNote{a} & 108 & 93 & 3.85 & 3.5\\
    Tesla & 6 & 258 & 110 & 3.08 \\
    Ford & 8 & 360 & 175\TblrNote{b} & 3.15 & 32.6 \\
    \bottomrule
\end{longtblr}
\end{document}

enter image description here

Note: I used the default TblrNote command to insert usual table notes. To add the custom note I changed the remark template and inserted that as a new theme.

Related Question