# [Tex/LaTex] How to change the font for chapter title with titlesec and titling under XeTeX

fontsfontspectitlesectitlingxetex

I'm using XeTeX to edit a document in which I am trying to use titlesec and titling to set a different font for some headings.

I'm using the approach suggested as a reply to a similar question, but so far my success is really partial.

The section and subsection titles change the font as desired, but the chapter title ignores the setting.

Here is a snippet of my code

%%% to allow custom headings
\usepackage{titlesec}
% to change titles font family
\usepackage{titling}

%%% declare fonts and set some formats
% fontspec to use non-latex with xetex
\usepackage{xunicode}
\usepackage{fontspec}
\usepackage{xltxtra}

% font declaration and title settings


The chapter setting is something I tried while mimicking the solution provided in the link above. I learnt that removing the * is required somehow as the easy mode would not work with chapter titles. I didn't find why, yet. But truth is that removing the asterisk also gets rid of the error… but it doesnt seem to work regarding the font face setting.

Any ideas?

Thanks 🙂

Edit: I found a really silly error, that led me to a (partial) solution and a new error showing up. I just set \documentclass{book} and now the renderer tries to put the desired font, but titlesec throws an error:

Titles must not be nested

The LaTeX code is this:

\begin{document}

\chapter{First Chapter}

The title above does not show any font.

\section{First Section}

Works as desired.

\subsection{Subsection}

Hiya! This also shows up as expected.

\subsubsection{Subsubsection}

We have not declared a titleformat for this heading, and so it is shown with the default font.

\section{Second section}

Repeating the success

\end{document}


The chapter title is the one that triggers the titlesec error.

The line

\titleformat{\chapter}{\LARGE\headingfont}


is the culprit. The syntax is wrong. The right one is

\titleformat{\chapter}[display]


So, the MWE (I've used Arial instead of Armata since I don't have that font installed):

\documentclass{book}
\usepackage{titlesec}
% to change titles font family
\usepackage{titling}

%%% declare fonts and set some formats
% fontspec to use non-latex with xetex
\usepackage{xunicode}
\usepackage{fontspec}
\usepackage{xltxtra}

% font declaration and title settings
\titleformat{\chapter}[display]
\begin{document}

\chapter{First Chapter}

The title above does not show any font.

\section{First Section}

Works as desired.

\subsection{Subsection}

Hiya! This also shows up as expected.

\subsubsection{Subsubsection}

We have not declared a titleformat for this heading, and so it is shown with the default font.

\section{Second section}

Repeating the success

\end{document}


yields the following output