我想\sffamily
对所有元素使用threeparttablex
' ThreePartTable
--- 标题、正文和注释 --- 就像下面对常规的 所做的那样threeparttable
。我设法更改了标题和注释,但我不知道如何更改表格主体。
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage[referable,para,flushleft]{threeparttablex}
% Use \sffamily in table
\newcommand{\tablefont}{\sffamily}
\makeatletter
\renewenvironment{table}[1][\fps@table]{
\edef\@tempa{\noexpand\@float{table}[#1]}
\@tempa
\tablefont%
}{
\end@float
}
\makeatother
\setTableNoteFont{\sffamily}% Use \sffamily for ThreePartTable's table notes
\usepackage[font=sf]{caption}% Use \sffamily in captions
\begin{document}
\begin{table}
\centering
\begin{threeparttable}
\caption{table}
\begin{tabular}{l l l}
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
First line\tnotex{tn:a} & 123 & 456 \\
Second line\tnotex{tn:b} & 123 & 456 \\
Third line & 123 & 456 \\
Fourth line & 123 & 456 \\
Fifth line & 123 & 456 \\
Sixth line & 123 & 456 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\item[a] \label{tn:a} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\item[b] \label{tn:b} Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\source Made up
\end{tablenotes}
\end{threeparttable}
\end{table}
\begin{ThreePartTable}
\begin{TableNotes}
\item[a] \label{tn:a} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\item[b] \label{tn:b} Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\source Made up
\end{TableNotes}
\begin{longtable}{l l l}
\caption{ThreePartTable}\\
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
\endfirsthead
\bottomrule
\insertTableNotes\\
\endlastfoot
First line\tnotex{tn:a} & 123 & 456 \\
Second line\tnotex{tn:b} & 123 & 456 \\
Third line & 123 & 456 \\
Fourth line & 123 & 456 \\
Fifth line & 123 & 456 \\
Sixth line & 123 & 456 \\
\end{longtable}
\end{ThreePartTable}
\end{document}
答案1
我更喜欢使用通用钩子。由于您要求仅在 和 内更改字体threeparttable
,ThreePartTable
因此我将字体更改限制在这些环境中。
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage[referable,para,flushleft]{threeparttablex}
\usepackage{caption}
% Use \sffamily in threeparttable and ThreePartTable
\newcommand{\tablefont}{\sffamily}
\AddToHook{env/threeparttable/begin}{%
\tablefont
\captionsetup{font=sf}% Use \sffamily in captions
}
\AddToHook{env/ThreePartTable/begin}{%
\tablefont
\captionsetup{font=sf}% Use \sffamily in captions
}
\setTableNoteFont{\sffamily}% Use \sffamily for ThreePartTable's table notes
\begin{document}
Test text.
\begin{table}[h!]
\centering
\begin{threeparttable}
\caption{table}
\begin{tabular}{l l l}
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
First line\tnotex{tn:a} & 123 & 456 \\
Second line\tnotex{tn:b} & 123 & 456 \\
Third line & 123 & 456 \\
Fourth line & 123 & 456 \\
Fifth line & 123 & 456 \\
Sixth line & 123 & 456 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\item[a] \label{tn:a} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\item[b] \label{tn:b} Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\source Made up
\end{tablenotes}
\end{threeparttable}
\end{table}
\begin{ThreePartTable}
\begin{TableNotes}
\item[a] \label{tn:a} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\item[b] \label{tn:b} Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\source Made up
\end{TableNotes}
\begin{longtable}{l l l}
\caption{ThreePartTable}\\
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
\endfirsthead
\bottomrule
\insertTableNotes\\
\endlastfoot
First line\tnotex{tn:a} & 123 & 456 \\
Second line\tnotex{tn:b} & 123 & 456 \\
Third line & 123 & 456 \\
Fourth line & 123 & 456 \\
Fifth line & 123 & 456 \\
Sixth line & 123 & 456 \\
\end{longtable}
\end{ThreePartTable}
Test text.
\end{document}
替代建议:重新定义两个环境中的正常字体系列。
\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage[referable,para,flushleft]{threeparttablex}
\usepackage{caption}
% Use \sffamily in threeparttable and ThreePartTable
\newcommand{\tablefont}{\renewcommand\familydefault\sfdefault\normalfont}
\AddToHook{env/threeparttable/begin}{%
\tablefont
}
\AddToHook{env/ThreePartTable/begin}{%
\tablefont
}
\begin{document}
Test text.
\begin{table}[h!]
\centering
\begin{threeparttable}
\caption{table}
\begin{tabular}{l l l}
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
First line\tnotex{tn:a} & 123 & 456 \\
Second line\tnotex{tn:b} & 123 & 456 \\
Third line & 123 & 456 \\
Fourth line & 123 & 456 \\
Fifth line & 123 & 456 \\
Sixth line & 123 & 456 \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\item[a] \label{tn:a} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\item[b] \label{tn:b} Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\source Made up
\end{tablenotes}
\end{threeparttable}
\end{table}
\begin{ThreePartTable}
\begin{TableNotes}
\item[a] \label{tn:a} Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\item[b] \label{tn:b} Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\source Made up
\end{TableNotes}
\begin{longtable}{l l l}
\caption{ThreePartTable}\\
\toprule
Column 1 & Column 2 & Column 3 \\
\midrule
\endfirsthead
\bottomrule
\insertTableNotes\\
\endlastfoot
First line\tnotex{tn:a} & 123 & 456 \\
Second line\tnotex{tn:b} & 123 & 456 \\
Third line & 123 & 456 \\
Fourth line & 123 & 456 \\
Fifth line & 123 & 456 \\
Sixth line & 123 & 456 \\
\end{longtable}
\end{ThreePartTable}
Test text.
\end{document}
结果将与之前显示的相同。