我需要格式化文档中的表格和图片的标题,使其使用 10pt Arial 字体加粗。主字体是 12pt Times New Roman。我尝试了以下方法 (MWE),但似乎不起作用。我使用的是 XeLaTex。
\documentclass[12pt]{article}
\usepackage{threeparttable}
\usepackage{caption}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\newfontfamily\myfont{Arial}
\DeclareCaptionFormat{mytabformat}{\myfont\fontsize{10pt}{0pt}\bf\tablename~\thetable. \selectfont #3}
\captionsetup[table]{format=mytabformat}
\begin{document}
Some text, which appears to be in Times New Roman.
\begin{table}[h]
\centering
\caption{Summary of some stuff, but my caption it is not Arial font.}
\begin{tabular}{c c c }
\hline
Group & Value & Description \\
\hline
1 & 22 & Something\\
2 & 29 & Insightful\\
\hline
\end{tabular}
\end{table}
{\fontspec{Arial} Some more text (in Arial), just to be sure.}
\begin{table}[h]
\centering
\begin{threeparttable}
\caption{Summary of some stuff, but my caption it is not Arial font. threeparttable is not the problem}
\begin{tabular}{c c c }
\hline
Group & Value & Description \\
\hline
1 & 22 & Something\\
2 & 29 & Insightful\\
\hline
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}
任何帮助,将不胜感激?
答案1
你使用的\bf
那个已经被弃用了 20 年的东西,而且放在了\selectfont
错误的地方。也是\fontsize{10}{0}
错误的。
\documentclass[12pt]{article}
\usepackage{threeparttable}
\usepackage{caption}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\DeclareCaptionFormat{mytabformat}{%
\fontsize{10pt}{12pt}\sffamily\bfseries\tablename~\thetable. #3%
}
\captionsetup[table]{format=mytabformat}
\begin{document}
Some text, which appears to be in Times New Roman.
\begin{table}[h]
\centering
\caption{Summary of some stuff, but my caption it is not Arial font.}
\begin{tabular}{c c c }
\hline
Group & Value & Description \\
\hline
1 & 22 & Something\\
2 & 29 & Insightful\\
\hline
\end{tabular}
\end{table}
{\sffamily Some more text (in Arial), just to be sure.}
\begin{table}[h]
\centering
\begin{threeparttable}
\caption{Summary of some stuff, but my caption it is not Arial font.
threeparttable is not the problem}
\begin{tabular}{c c c }
\hline
Group & Value & Description \\
\hline
1 & 22 & Something\\
2 & 29 & Insightful\\
\hline
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}