6

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:

Chapter font remain unchanged

while

See image.

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
  • 1
    @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
5

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}
  • This is the correct solution. Thank you very much. – 1amarr May 26 '16 at 21:18
3

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

enter image description here

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}
  • 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
1

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
\let\mt@makechapterhead\@makechapterhead
\makeatother


\begin{document}
\makeatletter
\let\@makechapterhead\mt@makechapterhead
\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}

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.