6

I'm writing a document using the book class. The normal chapter headings are of the form (for the first chapter in the book):

Chapter 1

<Name of first chapter>

Instead I would like it to be:

First chapter

< Name of first chapter>

and of course with "Second chapter" instead of "Chapter 2" and so forth. I don't have a lot of chapters, so if there is a method that involves manually entering the "First chapter" part, that would be acceptable. I think it would be necessary in fact, since the book is in Icelandic and I don't think Babel would support this sort of translation. So, for the record, I really want it to say "Fyrsti kafli" instead of "Chapter 1".

Ideally, this solution would also take care of the chapter name in the headers, but if not I can solve it by using

\markboth{First chapter. Name of first chapter}{1.1 Name of first subchapter}
lockstep
  • 250,273
Peter
  • 369
  • 1
    Welcome to TeX.SX! The titlesec and fmtcount packages should be able to do what you want. Unfortunately, the latter doesn't seem to support Icelandic at the moment. – egreg Jul 04 '15 at 23:14
  • Thanks, @egreg. You're correct, and the problem has been solved perfectly by Gonzalo Medina below, in the English case. If anyone has a solution that would work with Icelandic (or an arbitrary language), it would be much appreciated! – Peter Jul 04 '15 at 23:19
  • 1

1 Answers1

6

One option using titlesec and fmtcount (to easily get the ordinal string for the chapter counter); using fancyhdr and a simple redefinition for \chaptermark gives the desired formatting for the header:

\documentclass{book}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{titlesec}
\usepackage{fmtcount}
\usepackage{fancyhdr}
\usepackage{lipsum}% just for the example

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}
  {\Ordinalstring{chapter}~\chaptertitlename}
  {20pt}
  {\Huge}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[OL]{\leftmark}
\fancyhead[ER]{\nouppercase\rightmark}
\renewcommand{\chaptermark}[1]{%
  \markboth{\Ordinalstring{chapter}~\chaptername.\ #1}{}}

\begin{document}

\chapter{A test chapter}
\section{Test section}
\lipsum[1-6]

\end{document} 

The result:

enter image description here

Since, as egreg notices in his comment, fmtcount doesn't support Icelandic, one can use an \ifcase:

\documentclass{book}
\usepackage[icelandic]{babel}
\usepackage[a6paper]{geometry}% just for the example
\usepackage{titlesec}
\usepackage{fmtcount}
\usepackage{fancyhdr}
\usepackage{lipsum}% just for the example

\newcommand\icelandicordinal[1]{%
  \ifcase\value{#1}\or 
    Fyrsti\or 
    <second>\or...
    <third>%
  \fi
}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}
  {\icelandicordinal{chapter}~\MakeLowercase\chaptertitlename}
  {20pt}
  {\Huge}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[OL]{\leftmark}
\fancyhead[ER]{\nouppercase\rightmark}
\renewcommand{\chaptermark}[1]{%
  \markboth{\icelandicordinal{chapter}~\MakeLowercase\chaptername.\ #1}{}}

\begin{document}

\chapter{A test chapter}
\section{Test section}
\lipsum[1-6]

\end{document} 

The result:

enter image description here

Gonzalo Medina
  • 505,128
  • Since fmtcount doesn't support Icelandic, maybe a supplement showing how to define number-to-word translation for a few numbers could be useful: \ifcase\value{chapter}\or Fyrsti\or <second>\or...\fi – egreg Jul 04 '15 at 23:19
  • @egreg Of course. I missed the Icelandic part :-) Will add the addition shortly. Thanks. – Gonzalo Medina Jul 04 '15 at 23:20
  • @egreg Added a quick, yet provisional approach (I have to leave now). Later I'll polish the code (in particular, I'll read the fmtcount documentation to see if it provides an easier way to support languages). – Gonzalo Medina Jul 04 '15 at 23:31
  • That's more or less what I was thinking to, but i'd introduce a macro \icelandicordinal: \newcommand{\icelandicordinal}[1]{\ifcase\value{#1}\or Fyrsti\or <second>\or...\fi} – egreg Jul 04 '15 at 23:34
  • Thanks, @GonzaloMedina! Your addition is on the right track, but the word Kafli in "Fyrsti Kafli" should not be capitalised. – Peter Jul 04 '15 at 23:37
  • @Pétur. That can be easily done. When I return home (on the mobile now) I'll provide the code. By the way are you referring to the title, the header or both? – Gonzalo Medina Jul 04 '15 at 23:56
  • @GonzaloMedina I meant in both the title and header. It's grammatically incorrect to capitalise both words of "First chapter", at least in some languages. I imagine the same solution would work for both title and header, but I'm not familiar with it. I'll accept your answer as soon as you're finished. Thanks again! – Peter Jul 05 '15 at 00:23
  • @Pétur You're welcome! Answer updated with the necessary modifications. – Gonzalo Medina Jul 05 '15 at 01:22
  • @egreg Yes, the macro is a good idea. Thanks. I updated the answer. – Gonzalo Medina Jul 05 '15 at 01:23