1

How do you change the typeface used for the part environment to an Opentype font?

(In the MWE below, I've used a TrueType font, but the method should be the same).

It appears the standard titlesec method for chapter and section headings doesn't work.

Engine is LuaLaTeX.

M(n-)WE:

\documentclass[11pt, a4paper]{book}
\usepackage[raggedright]{titlesec}
\usepackage{fontspec}

\newfontfamily\partfont{Verdana.ttf}
\titleformat*{\part}{\partfont}

\newfontfamily\chapterfont{Verdana.ttf}
\titleformat*{\chapter}{\chapterfont}

\begin{document}
    \part{Hello world.}
    \chapter{Hello again, world.}
\end{document}
3

The \part command can't be changed using the “easy” mode. When you compile your code you get this error:

! Package titlesec Error: Not allowed in `easy' settings.

See the titlesec package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.7 \titleformat*{\part}{\partfont}

? h % < I typed h<return> here
The sectiong command you are trying to redefine
is not handled by the starred variant (eg, \part)
? 

You'll have to use the general form of the \titleformat macro (i.e. without the *) and replicate the \part command from book class. Use this \titleformat:

\titleformat{\part}
  {\filcenter\huge\bfseries} % Format of the section header
  {\partname\nobreakspace\thepart} % Format of the “Part X” text
  {0pt} % Horizontal space (none, we want vertical)
  {\\\vspace{20pt}\Huge} % Commands before the title part (vertical space of 20 pt and increase in font size

The \chapter command allows you to use \titleformat*, so your code works.

Now you just have to add in your custom font. I used TeX Gyre Termes for I don't have Verdana.ttf:

\documentclass[11pt, a4paper]{book}
\usepackage[raggedright]{titlesec}
\usepackage{fontspec}

\newfontfamily\partfont{Tex Gyre Termes}
\titleformat{\part}
  {\filcenter\huge\bfseries\partfont}
  {\partname\nobreakspace\thepart}
  {0pt}
  {\\\vspace{20pt}\Huge}

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}

\newfontfamily\chapterfont{Tex Gyre Termes}
\titleformat*{\chapter}{\normalfont\huge\bfseries\chapterfont}

\begin{document}
    \part{Hello world.}
    \chapter{Hello again, world.}
\end{document}

Part heading:

enter image description here

Chapter heading:

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.