8

I cannot find a way to change chapter style with babel included (for hungarian language). Here is the example:

\documentclass[a4paper]{report}
\usepackage[magyar]{babel}
\usepackage{titlesec}

\titleformat{\chapter}[hang]
{\normalfont}
{\LARGE\thechapter.}
{10pt}
{\LARGE\MakeUppercase}
[\normalfont]
\titlespacing{\chapter}{0pt}{0pt}{30pt}[0pt]

\begin{document}
\chapter{First chapter}
\end{document}

If I comment out the \usepackage[magyar]{babel} line, everything works as expected, however, with babel it does not work. Is it possible to style chapters (and sections, etc.) while using babel?

  • Sorry, but I don't get any error. What TeX distribution are you using? – egreg May 23 '13 at 19:53
  • I don't get an error either. (MiKTeX 2.9 last time updated 2 weeks ago) – Dominic Michaelis May 23 '13 at 19:55
  • I'm using MikTeX 2.9, but I do not get any error, but chapter does not look like I specified with \titleformat, but looks like babel's default. With english babel \usepackage[english]{babel} it works properly. – Gergely May 23 '13 at 20:04
  • 4
    The magyar module for babel does a lot of stuff \AtBeginDocument and this might be the cause. One possible workaround is to move the \titleformat and \titlespacing commands after \begin{document}. – Gonzalo Medina May 23 '13 at 20:20
  • 3
    The Hungarian support module for Babel restores the meaning of \chapter after \begin{document}, while not giving any method for overriding this choice. – egreg May 23 '13 at 22:55
2

The magyar module for babel does a lot of stuff \AtBeginDocument; amongst other things (as egreg noticed in his comment), it restores the meaning of \chapter after \begin{document}, while not giving any method for overriding this choice. One possible workaround is to move the \titleformat and \titlespacing commands after \begin{document}:

\documentclass[a4paper]{report}
\usepackage[magyar]{babel}
\usepackage{titlesec}

\begin{document}

\titleformat{\chapter}[hang]
{\normalfont}
{\LARGE\thechapter.}
{10pt}
{\LARGE\MakeUppercase}
[\normalfont]
\titlespacing{\chapter}{0pt}{0pt}{30pt}[0pt]
\chapter{First chapter}

\end{document}

enter image description here

|improve this answer|||||
2

Actually I've found a way to solve this problem in package or class. Using \titleformat in \AtBeginDocument is useless, but the etoolbox has the \AfterEndPreamble{} macro which runs at the very end of the \begin{document}. Putting \titleformat into that makes titlesec work.

|improve this answer|||||

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.