[Tex/LaTex] Changing Caption Font Doesn’t Work

captionsfontspecxetex

I need to format the caption of tables and figures in my document so that is is 10pt Arial font bold faced. The main font is 12pt Times New Roman. I've tried the following (MWE), but it doesn't seem to work. I'm using 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} 

Any help would be appreciated?

Best Answer

You are using \bf that has been deprecated for 20 years and placing \selectfont in the wrong place. Also \fontsize{10}{0} is wrong.

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

enter image description here

Related Question