[Tex/LaTex] fontspec in book title

bookschaptersfontspectitles

I have the following code:

\documentclass{book}
\usepackage{fontspec}
\begin{document}
    \part{title}
    \chapter{\fontspec{Latin Modern Roman} chapter title}
    \part{title}
    \chapter{title}
\end{document}

I use package fontspec to switch font from one to another. As in this code, I want to typeset the chapter title using font Latin Modern Roman. Actually, it works fine with report and memoir class. But it produce an error in book class. How can I fix it?

Best Answer

Using the scrbook-class of KOMA-Script:

Serif-Font in all headings (chapter, section, etc.)

\documentclass{scrbook}

\usepackage{fontspec}
\addtokomafont{disposition}{\rmfamily}

\begin{document}

\chapter{Hello World}
Test
\end{document}

Or explicitly set the font with fontspec:

\documentclass{scrbook}

\usepackage{fontspec}
\newfontfamily{\headingsfont}{Latin Modern Roman}
\addtokomafont{disposition}{\headingsfont}

\begin{document}

\chapter{Hello World}
Test
\end{document}

The result is identical if the standard serif font is Latin Modern Roman, you can set this with \setromanfont{<fontname>}:

result

If you just want to change certain structure elements use e.g. \addtokomafont{chapter}{} or \addtokomafont{section}{} etc:

\documentclass[open=any]{scrbook}

\usepackage{fontspec}
\setmainfont{Tex Gyre Pagella}
\newfontfamily{\partnumfont}{Comic Sans MS}
\newfontfamily{\partfont}{Latin Modern Roman}
\newfontfamily{\chapterfont}{Tex Gyre Chorus}
\newfontfamily{\sectionfont}{Tex Gyre Heros}    
\usepackage{xcolor}

\addtokomafont{partnumber}{\color{red}\partnumfont}
\addtokomafont{part}{\partfont}
\addtokomafont{chapter}{\chapterfont}
\addtokomafont{section}{\sectionfont}}

\begin{document}
\part{Test}
\section{my first Koma-Script book}
\end{document}

enter image description here

Using the standard book class and package titlesec:

You probably need to adjust the settings.

\documentclass{book}
\usepackage{fontspec}
\setmainfont{Tex Gyre Pagella}
\newfontfamily{\partfont}{Tex Gyre Heros}
\newfontfamily{\chapterfont}{Tex Gyre Chorus}
\newfontfamily{\sectionfont}{Tex Gyre Heros}        
\usepackage{xcolor}

\usepackage{titlesec}
\titleformat{\part}[display]{\partfont\Huge\bfseries\centering}{\partname\ \thepart}{20pt}{}
\titleformat{\chapter}{\chapterfont\huge\bfseries}{\chaptername\ \thechapter}{20pt}{}
\titleformat{\section}{\sectionfont\large\bfseries}{\thesection}{20pt}{}

\begin{document}
\part{Test}
\chapter{Hello Worl.}
\section{standard book}
Hello World!
\end{document}
Related Question