Why can't sectsty change the chapter font when it's used with babel package?
The magyar
option seizes the initiative and changes the code for \@chapter
to reflect the original code in the class and ignores the settings by sectsty
. It does nothing to \@schapter
, which is the reason you see sans serif in unnumbered chapters.
Use titlesec
, instead:
\documentclass[a4paper]{report}
\usepackage[sf,bf]{titlesec}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\newcommand\magyarOptions{chapterhead=unchanged}
\usepackage[magyar]{babel}
\usepackage{blindtext}
\renewcommand{\sfdefault}{qhv}
\titleformat{\chapter}[display]
{\sffamily\bfseries\huge}
{\thechapter. \chaptername}
{20pt}
{}
\begin{document}
\chapter{Example chapter} %% this one is not working correctly
\blindtext
\section{Example section}
\blindtext
\subsection{Example subsection}
\blindtext
\chapter*{Example unnumbered chapter}
\blindtext
\end{document}
Use \def\magyarOptions{chapterhead=unchanged}
before \usepackage[magyar]{babel}
Code:
\documentclass[a4paper]{report}
\def\magyarOptions{chapterhead=unchanged}
\usepackage[magyar]{babel}
\usepackage[utf8]{inputenc}
\usepackage{t1enc}
\usepackage{blindtext}
\usepackage{sectsty}
\chapterfont{\usefont{T1}{qhv}{b}{n}\selectfont\huge}
\sectionfont{\usefont{T1}{qhv}{b}{n}\selectfont\LARGE}
\subsectionfont{\usefont{T1}{qhv}{b}{n}\selectfont\Large}
\begin{document}
\chapter{Example chapter} %% this one is not working correctly
\blindtext
\section{Example section}
\blindtext
\subsection{Example subsection}
\blindtext
\chapter*{Example unnumbered chapter}
\blindtext
\end{document}