[Tex/LaTex] Changing font took boldness from section and subsection titles

boldfonts

\documentclass{article}
\usepackage{titlesec}
\renewcommand{\rmdefault}{phv} % Arial
\renewcommand{\sfdefault}{phv} % Arial
\titleformat{\thesection}
  {\normalfont\fontsize{12}{15}\bfseries}{\thesection}{1em}{}
\titlelabel{\thetitle.\quad}

\begin{document}

\section{Test Section}
test
\subsection{Subsection}
test

\end{document}

I achieved to change font type to Arial but bold appearances of titles are gone. Is there a way to solve it?

Best Answer

Using fontspec

The fontspec package can load any TrueType or OpenType font, which include all the fonts you can use in a word processor. It only works with lualatex or xelatex, not pdflatex.

\documentclass{article}
\usepackage{titlesec}
\usepackage{fontspec}

\setmainfont{TeX Gyre Heros}
\defaultfontfeatures{Scale=MatchUppercase}
\setsansfont{TeX Gyre Heros}

\titleformat{\thesection}
  {\sffamily\fontsize{12}{15}\upshape\bfseries}{\thesection}{1em}{}
\titlelabel{\thetitle.\quad}

\begin{document}

\section{Test Section}
test
\subsection{Subsection}
test

\end{document}

You can change TeX Gyre Heros to Arial if you want to use Arial. They are similar, but not quite the same. Heros is closer to what you get when you select phv, and computers with no Microsoft software might not have Arial installed.

Using NFSS

The web page you found that claims that code will switch to Arial is not correct. Arial and Helvetica are similar, but not the same.

You want the helvet package, which is part of psnfss. You are telling the system to use the default PostScript Helvetica font, which on many systems is TeX Gyre Heros, but you do not load any of the font encodings it supports. If you check, you should be getting an error message that says the shape phv/bx/n is not available (because it’s looking for them in the wrong encoding). Here, I load the encodings T1 and TS1.

If you want to control which Helvetica clone the document uses, you can replace \usepackage{helvet} with \usepackage{tgheros}. A version of Arial from URW might also be available, as \usepackage{uarial}.

I also took the liberty of redefining \familydefault rather than \rmdefault.

\documentclass{article}
\usepackage[T1]{fontenc} % Instead of OT1, which qhv does not support.
\usepackage{textcomp} % Also load TS1
\usepackage[utf8]{inputenc} % The default since April 2018.
\usepackage{titlesec}
\usepackage{helvet} % Likely tgheros.

\renewcommand{\familydefault}{\sfdefault}

\titleformat{\thesection}
  {\sffamily\fontsize{12}{15}\upshape\bfseries}{\thesection}{1em}{}
\titlelabel{\thetitle.\quad}

\begin{document}

\section{Test Section}
\textsf{\textbf{test}}
\subsection{Subsection}
test

\end{document}
Related Question