5

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
\newfontfamily\headingfont[]{Armata}
\titleformat{\chapter}{\LARGE\headingfont}
\titleformat*{\section}{\LARGE\headingfont}
\titleformat*{\subsection}{\Large\headingfont}
\renewcommand{\maketitlehooka}{\headingfont}

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.

  • Have you tried using sectsty instead of titlesec - I haven't used the latter, but I found sectsty quite easy to use. – FionaSmith Mar 26 '14 at 18:54
6

The line

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

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

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

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

\documentclass{book}
%%% 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
\newfontfamily\headingfont[]{Arial}
\titleformat{\chapter}[display]
  {\huge\headingfont}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat*{\section}{\LARGE\headingfont}
\titleformat*{\subsection}{\Large\headingfont}
\renewcommand{\maketitlehooka}{\headingfont}
\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

enter image description here

  • @versvs You're welcome. Happy to help. – karlkoeller Mar 27 '14 at 11:21

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.