# Why can't sectsty change the chapter font when it's used with babel package?

I'm using Latex to write my thesis in Hungarian, so I include in the preamble the following:

\usepackage[magyar]{babel}


Once this is loaded, I get "Chapter", "Figure", etc. in Hungarian and with matching typography.

I would like to use a sans-serif font in chapter, section and subsection headings. To achieve this, I use the sectsty package, set up like this:

\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}


LaTeX correctly sets sections and subsections in TeX Gyre, but chapter headings stay unchanged, while unnumbered chapters (\chapter*{...}) get changed like they are supposed to.

Example:

while

I suspect the conflict is caused by babel, which redefines the chapter heading in some way sectsty won't be able to handle.

Does anyone have any idea how to manage this? I have tried titlesec, but it behaves in the same way.

Thank you!

Edit:

I created a short document with every relevant package to recreate the problem:

\documentclass[a4paper]{report}
\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}


If I comment out babel, sectsty works as expected but I lose the localization obviously.

• Welcome to TeX.SX! Please post a compilable document, not just fragments only – user31729 May 26 '16 at 20:23
• Please also tell us which document class you use. – Mico May 26 '16 at 20:26
• I use report, since I need chapters and article doesn't have those. I can post a compilable document, but where can I submit it? As an answer? – 1amarr May 26 '16 at 20:29
• You can edit your own question to post code. – Mico May 26 '16 at 20:32
• @1amarr: I experimented with basically any European language setting for babel and magyar is the only one that fails here. I assume, it's magyar.ldf, but I am not sure – user31729 May 26 '16 at 21:05

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}

\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}

• This is the correct solution. Thank you very much. – 1amarr May 26 '16 at 21:18

Use \def\magyarOptions{chapterhead=unchanged} before \usepackage[magyar]{babel}

Code:

\documentclass[a4paper]{report}
\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}

• Thank you. It's close, but I need the heading displayed as "n. fejezet" where "n" is the number of the chapter. – 1amarr May 26 '16 at 21:15

Here is a solution

\documentclass[a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{t1enc}
\usepackage[magyar]{babel}

\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}
\makeatletter
\makeatother

\begin{document}
\makeatletter
\makeatother
\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}