Change font for chapter, section, headings in Latex document

ebgaramondfontspecsectioning

Would like to preface this by saying that I am fairly new to Latex. My query is that I would like to change the font for my chapter, section and subsection headings to raleway while keeping the font for the entire document to be EBGaramond. I am adding the code for the same below

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{raleway}
\usepackage{ebgaramond}



\usepackage{titlesec}
\titleformat{\chapter}
  [display]
  {\Huge\bfseries\raleway}
  {\huge\chaptertitlename\space\thechapter}
  {20pt}
  {}

\titleformat*{\section}{\normalfont\Large\bfseries\raleway}
\titleformat*{\subsection}{\normalfont\large\bfseries\raleway}

\usepackage{blindtext}% dummy text
\begin{document}
\tableofcontents
\blinddocument
\end{document}

With this code, everything is typesetted to EBGaramond. How do I fix this?

I am using pdflatex compiler in overleaf, if that is useful information.

Best Answer

The answer is in Ulrike Fischer`s comment. I only added the code for completeness.

Using pdflatex

b

% !TeX TS-program = pdflatex

\documentclass{book}
%\usepackage[T1]{fontenc} % loaded by raleway
\usepackage[extrabold]{raleway}
\usepackage{ebgaramond}

\usepackage{titlesec}
\titleformat{\chapter}
[display]
{\sffamily\Huge\bfseries}
{\huge\chaptertitlename\space\thechapter}
{20pt}
{}

\titleformat*{\section}{\sffamily\Large\bfseries}
\titleformat*{\subsection}{\sffamily\large\bfseries}

\usepackage{kantlipsum}% dummy text

\begin{document}
    \chapter{Heading on level 0}
    \kant[1]

    {\sffamily \small   \kant[1]}       

\end{document}

Using xelatex or lualatex there are more possibilities.

c

% !TeX TS-program = xelatex

\documentclass{book}
%   \RequirePackage{fontspec} % loaded by raleway
\usepackage{raleway}
\usepackage{ebgaramond}

\usepackage{titlesec}
\titleformat{\chapter}
[display]
{\ralewayextra\Huge\bfseries}
{\huge\chaptertitlename\space\thechapter}
{20pt}
{}

\titleformat*{\section}{\ralewayextra\Large\bfseries}
\titleformat*{\subsection}{\ralewayextra\large\bfseries}

\usepackage{kantlipsum}% dummy text

\begin{document}
    \chapter{Heading on level 0}
    \kant[1]
    
    {\ralewaylight \small   \kant[1]}
    
    {\ralewayLF \small  \kant[1]}       

\end{document}
Related Question