# Issues with changing fonts for text and captions

I need to set my fonttypes globally to be Times New Roman for text, and Arial for figure and table captions.

Normally I'm somewhat seasoned to latex, but here I'm pretty much running in a wall.

One of several things I tried to do: Change the interpreter to Xelatex and add the following lines in the preamble:

\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}


However, before I even progress to the next step of defining captions, the second I use fontspec, I mess up all the other formatting that I have done for the document. Everything gets a weird font, section titles are no longer bold, etc.

Is there a nonintrusive way to do change fonts that does not wreck everything?

I tried to google it and have a million tabs open because of it. So far no luck. But I can't believe something as essential and simple as changing font types can't have a hazzlefree way of doing it, so here I am. Thank you in advance.

Additional info: This project is a colab, so I'm using overleaf.

More additional info: I was asked to provide my very lengthy preamble, so here it is. But I'm pretty sure that the issue isn't with the preamble itself since the moment fontenc gets activated it just straight up ignores the stuff.

\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
%\input{fontchange}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mathptmx}       %different looking math font
%\usepackage{mathtimes}
\usepackage{xcolor}
%\usepackage[framed, numbered]{matlab-prettifier} For matlab code
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{fancyhdr}   % for headers, footers and pagenumbering
\usepackage{multicol}
\usepackage{multirow}
\usepackage{lastpage}   % so {page of page} works
\usepackage{float}      % for images and figures
%\usepackage{cleveref}   % for referencing subfigs
\usepackage{subcaption} % no need to explauin
%\usepackage[flushleft]{threeparttable}  %for notes under tables
%\usepackage[english]{nomencl}
\usepackage{lipsum}     % dummy text package
\usepackage{siunitx}
\usepackage{array}
\usepackage{tabularx}
\usepackage{pifont}      %allows use of special characters, use \ding{xx}
\usepackage{caption}
\usepackage{subcaption}  %for sub figure environment
\usepackage{titlesec}    %package for formatting title spacing !
\usepackage{parskip}     % paragraph skip
\usepackage{geometry}        % Document margins
\usepackage{todonotes}   % self explanatory
%\usepackage[sc]{helvet} %helvetica text
\usepackage{graphicx}   % Allows including images
\usepackage{booktabs}   % Allows the use of \toprule, \midrule and \bottomrule in tables
\usepackage[final]{pdfpages} %for including pdf's
% Hyper References
\hypersetup{
citecolor=black,
urlcolor=black, %blue for blue obv.
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode} %for matlab code
\usepackage{mwe}
% References
\usepackage[backend=biber,
style=numeric,
citestyle=ieee,
%backref=true,
abbreviate=false,
dateabbrev=false,
alldates=long]{biblatex}
%\usepackage{showframe}      % used to show the document size
\usepackage{multicol}   %for several columns in a document
\setlength{\columnsep}{7mm}
\addtolength{\skip\footins}{10pt plus 3pt minus 3pt}    %spacing of footnotes
\renewcommand\footnoterule{\kern -3pt \hrule width 50mm \kern 2.6pt}
%Geometry of the pagelayout
\geometry{a4paper, textheight=720pt, left=25mm, right=25mm, top=25mm, footskip=12mm, headsep=6mm}
\setlength {\marginparwidth }{22mm} % for the todonotes package

%---------------- DOCUMENT FORMATING -------------------------
%spacing of white vertical space above and below equations
\setlength{\abovedisplayskip}{14pt plus 2pt minus 2pt}
\setlength{\belowdisplayskip}{14pt plus 2pt minus 2pt}

%%%% FORMAT CAPTIONS %%%%%%
\usepackage[font=footnotesize,labelfont=bf,labelsep=period,textfont=sl]{caption}
\captionsetup[table]{skip=3pt, position=top}
\captionsetup[figure]{skip=6pt, belowskip=0pt}
\captionsetup[subfigure]{skip=6pt, belowskip=0pt}
\setlength{\intextsep}{14pt plus 2pt minus 2pt} %spacing between
%\setlength{\floatsep}{20pt plus 1.0pt minus 2.0pt}
\setlength{\captionmargin}{20pt}                % caption woun't go full width

\titlespacing{\section}      {0em}{2.5em}{.6em}
\titlespacing{\subsection}   {0em}{1.50em}{.2em}
\titlespacing{\subsubsection}{0em}{1.0em}{0.2em}
\titlespacing{\paragraph}    {0em}{.25em}{.25em}

\setlength{\parskip}{0.em}           %length of paragraph skip
%%%%% Format font size %%%%%%%%%%
\titleformat{\Section}
{\normalfont\large\bfseries}{\thesection}{1em}{}

\titleformat{\Subsection}
{\normalfont\normalsize\bfseries}{\thesubsection}{1em}{}

\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}

\setcounter{secnumdepth}{3}     %number before section title up to 3rd level
\setcounter{tocdepth}{2}        % 2 levels of toc

\counterwithin{table}{section}
\counterwithin{figure}{section}
\numberwithin{equation}{section}
% --- set footer and header ---
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0pt}  % bottomrule line thickness = 0
\setlength{\parindent}{0em}
\newlist{steps}{enumerate}{1}
\setlist[steps, 1]{leftmargin=1.5cm,label = Step \arabic*:}
\graphicspath{{graphics/}}

• Welcome to TeX SX! Normally, this is simply done with the caption package, adding \captionsetup{font=sf} to the preamble. Oct 6, 2020 at 12:11
• without knowing what your document is doing currently to setup fonts, it is quite impossible to tell you what to change. Normally using fontspec should work fine, but you often also need to remove packages not meant for xelatex. Oct 6, 2020 at 12:11
• @Bernard do I still have to use xelatex for it and do I have to upload fonts to overleaf for that? Oct 6, 2020 at 12:20
• @UlrikeFischer I can upload the preamble, which is quite lengthy, but I think the issue I'm having is more in-depth than that. Oct 6, 2020 at 12:20
• @UlrikeFischer I added the preamble. Oct 6, 2020 at 12:31

I just included a simple MWE build with xelatex to show some of the caption package options that I use often, (though not at the same time.)

% !TeX TS-program = xelatex

\documentclass[12pt,a4paper]{article}

\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}

\RequirePackage{booktabs}
\RequirePackage{graphicx}

\RequirePackage[%
dvipsnames, % Load a set of predefined colors
table      % Load the colortbl package
]{xcolor}

\RequirePackage{caption} %lots of options in the manual
\DeclareCaptionFont{gray}{\color{gray}}

\captionsetup[figure]{%
font={footnotesize,sf},%
name=Fig.,
format=hang,
justification=raggedright,
margin=15pt,
indention=0pt}

\captionsetup[table]{%   A
font=small,%
labelfont={gray,sf},
font={footnotesize,sf},%
textfont=it,
name=Table,
labelsep=newline,
skip=0.5\baselineskip,
justification=raggedright,
indention=0pt,
position=top}

\RequirePackage{kantlipsum} %dummy text

\begin{document}

\kant[1]

\begin{figure}
\centering
\includegraphics[height=150pt,keepaspectratio]{example-image-b}
\caption{Dummy image and caption example B}
\label{fig:B}
\end{figure}

\begin{center}
\begin{table}[htbp]
\centering
\caption{Simple table for testing captions}
\begin{tabular}{lcccc}
\toprule
& Column1 & \multicolumn{2}{c}{Columns 2-3} & Column 4 \\
\midrule
Sample & a     & \multicolumn{2}{c}{b} & c \\
perf  & 123   & \multicolumn{2}{c}{456} & 789 \\
\rowcolor[rgb]{ .816,  .808,  .808} assess & n/a   & \multicolumn{2}{c}{best} & normal \\
\bottomrule
\end{tabular}%
\end{table}%
\end{center}

\end{document}


UPDATE

It seems the culprit is \usepackage{mathptmx}. When you comment it everything else works fine. Even with the last version installed it seems to make trouble. (mathptmx.sty 2020/03/25 PSNFSS-v9.3 Times w/ Math, improved (SPQR, WaS) )

I compiled my little example with your full preamble, even mcode and some added \cite and a .bib file of my own. The only problem I found was with citestyle=ieee,. It seems there is an issue with the last update of biblatex', soon to be solved, so comment that line for now.

% !TeX TS-program = xelatex

\documentclass[12pt,a4paper]{article}

\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}

\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{mathptmx}       %different looking math font NOT WORKING

\RequirePackage{booktabs}
\RequirePackage{graphicx}

\RequirePackage[%
dvipsnames, % Load a set of predefined colors
table      % Load the colortbl package
]{xcolor}

\usepackage{titlesec}    %package for formatting title spacing !
%%%% FORMAT CAPTIONS %%%%%%
\usepackage[font=footnotesize,labelfont=bf,labelsep=period,textfont=sl]{caption}
\captionsetup[table]{skip=3pt, position=top}
\captionsetup[figure]{skip=6pt, belowskip=0pt}
\captionsetup[subfigure]{skip=6pt, belowskip=0pt}
\setlength{\intextsep}{14pt plus 2pt minus 2pt} %spacing between
%\setlength{\floatsep}{20pt plus 1.0pt minus 2.0pt}
\setlength{\captionmargin}{20pt}                % caption woun't go full width

\titlespacing{\section}      {0em}{2.5em}{.6em}
\titlespacing{\subsection}   {0em}{1.50em}{.2em}
\titlespacing{\subsubsection}{0em}{1.0em}{0.2em}
\titlespacing{\paragraph}    {0em}{.25em}{.25em}

\setlength{\parskip}{0.em}           %length of paragraph skip

\RequirePackage{kantlipsum} %dummy text
\RequirePackage{blindtext} %dummy text

\begin{document}

\Blinddocument
\blindmathpaper

\begin{figure}
\centering
\includegraphics[height=150pt,keepaspectratio]{example-image-b}
\caption{Dummy image and caption example B } %dummy text}}
\label{fig:B}
\end{figure}

\begin{center}
\begin{table}
\centering
\caption{Simple table for testing captions}
\begin{tabular}{lcccc}
\toprule
& Column1 & \multicolumn{2}{c}{Columns 2-3} & Column 4 \\
\midrule
Sample & a     & \multicolumn{2}{c}{b} & c \\
perf  & 123   & \multicolumn{2}{c}{456} & 789 \\
\rowcolor[rgb]{ .816,  .808,  .808} assess & n/a   & \multicolumn{2}{c}{best} & normal \\
\bottomrule
\end{tabular}%
`