2
\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?

  • 2
    Bold for me with your example. Please save the example to a file called oemerFonts.tex and run it. Please post the log file of that run. – Johannes_B Jul 1 '18 at 5:14
  • Please not, bananas are not apples and Helvetica is not Arial. – Johannes_B Jul 1 '18 at 5:15
  • I am also unable to reproduce the issue you say you're experiencing. Please tell us which TeX distribution you employ. – Mico Jul 1 '18 at 6:05
  • in texmaker's quick build section in settings when I use xeLaTeX + view PDF LuaLaTeX + view PDF problem is still in there. But change to pdfLaTeX view PDF solve the problem for MWE but this setting can't compile my original doc. – ömer koçhan Jul 1 '18 at 7:02
  • 1
    With Lua/XeLaTeX, you need to use a different method of choosing fonts. See the fontspec way below. – Johannes_B Jul 1 '18 at 9:34
3

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}
  • 1
    OP uses phv, not qhv. – Johannes_B Jul 1 '18 at 5:58
  • Corrected the references to qhv. Thanks. – Davislor Jul 1 '18 at 6:23
2

Running your example with XeLaTeX or LuaLaTeX issues

LaTeX Font Warning: Font shape `TU/phv/m/n' undefined
(Font)              using `TU/lmr/m/n' instead on input line 9.

LaTeX Font Warning: Font shape `TU/phv/bx/n' undefined
(Font)              using `TU/phv/m/n' instead on input line 11.

which clearly shows the origin of your problems.

With XeLaTeX or LuaLaTeX you need fontspec for defining fonts.

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

\setmainfont{Arial}
\setsansfont{Arial}

\titleformat{\section}
  {\normalfont\fontsize{12}{15}\bfseries}
  {\thesection}
  {1em}
  {}
\titlelabel{\thetitle.\quad}

\begin{document}

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

\end{document}

Note it's \titleformat{\section}, not \titleformat{\thesection}. And Arial is not Helvetica.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.