在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
并将其作为新主题插入。