如何使用 longtable + threeparttablex 格式化表格注释?

如何使用 longtable + threeparttablex 格式化表格注释?

threeparttable常规tabular环境中,我能够通过添加自定义注释来实现格式设置(左对齐,跨越整个表格宽度,没有标签,同时保持表格脚注缩进)外部环境tablenotes(但在threeparttable环境内,请参见下面的代码和屏幕截图中的表 1)。

现在我尝试使用组合threeparttablex+复制此格式longtable,但我很难达到相同的效果。到目前为止,唯一可行的选择似乎是将其添加到下面insertTableNotes。但这样,自定义注释将被视为增加表格宽度的普通行,而不是被换行:

在此处输入图片描述

是否有人有解决方案,可以复制表 1 的格式,而无需手动指定表宽度?

笔记:\note我不使用该命令或flushleft选项的原因threeparttablex是:1)我希望能够传递没有标签的注释;2)flushleft不能完美地左对齐文本。

\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

这是使用该包的解决方案tabularray

\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}

在此处输入图片描述

注意:我使用默认TblrNote命令插入常用表格注释。为了添加自定义注释,我更改了模板remark并将其作为新主题插入。

相关内容