0

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}
1
  • You can use the longtblr environment of the tabularray package to achieve the 2 effects you have mentioned in the note.
    – Imran
    Jan 4, 2022 at 16:56

1 Answer 1

1

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.

4
  • Thank you so much! I had actually come across the tabularray package but stayed away from it because it wouldn't compile (being Latex3). Now I found out that the regular Overleaf will compile it if you choose the newest Tex Live distribution (2021) while my university's Overleaf/sharelatex distribution still only offers the 2020 edition.
    – dufei
    Jan 4, 2022 at 18:07
  • @dufei You can compile with 2020 edition if you add the sty file in your working project (though I am not sure if it is possible to add an sty file while using your university's distribution). You may find the sty file here.
    – Imran
    Jan 4, 2022 at 18:24
  • 1
    That works indeed! Now I will need to wrap my head around the new syntax (e.g., how to change the font for the superscript letters) but the documentation seems quite good. Thanks again!
    – dufei
    Jan 4, 2022 at 18:29
  • I think all table related things can be done using only this package. So, learning this package is a worth shot.
    – Imran
    Jan 4, 2022 at 18:37

You must log in to answer this question.

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