How can I change the chapter heading of the book class to typeset centered chapter names as shown in the image above?

Asked
Active
Viewed 4.2k times
20
yannisl
- 117,160
2 Answers
27
Depends on your level of expertise, if you are more comfortable with packages then using titlesec as suggested by Seamus in the comments is a good choice. If you are here to learn a bit more about the innards of LaTeX you can use the code below, which uses the LaTeX @makechapterhead and @makeschapterhead macros (note the make(s) in the latter). The one is used to handle the normal version of chapter and the other the starred version. It is good practice to update both of them when you are developing or modifying a class. The code can be found in book.cls.

\documentclass[oneside]{book}
\usepackage[english]{babel}
\usepackage{lipsum}
\makeatletter
\def\thickhrule{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\position{\centering}
%% Note the difference between the commands the one is
%% make and the other one is makes
\renewcommand{\@makechapterhead}[1]{%
\vspace*{10\p@}%
{\parindent \z@ \position \reset@font
{\Huge \scshape \thechapter }
\par\nobreak
\vspace*{10\p@}%
\interlinepenalty\@M
\thickhrule
\par\nobreak
\vspace*{2\p@}%
{\Huge \bfseries #1\par\nobreak}
\par\nobreak
\vspace*{2\p@}%
\thickhrule
\vskip 40\p@
\vskip 100\p@
}}
%% This uses makes
\def\@makeschapterhead#1{%
\vspace*{10\p@}%
{\parindent \z@ \position \reset@font
{\Huge \scshape \vphantom{\thechapter}}
\par\nobreak
\vspace*{10\p@}%
\interlinepenalty\@M
\thickhrule
\par\nobreak
\vspace*{2\p@}%
{\Huge \bfseries #1\par\nobreak}
\par\nobreak
\vspace*{2\p@}%
\thickhrule
\vskip 100\p@
}}
\begin{document}
\chapter{The Real Numbers}
\lipsum[1-2]
\chapter*{The Imaginary Numbers}
\lipsum[1-2]
\end{document}
yannisl
- 117,160
21
Here's an example using titlesec.
\documentclass{book}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\bfseries\filcenter}
{\LARGE\thechapter}
{1ex}
{\titlerule[2pt]
\vspace{2ex}%
\LARGE}
[\vspace{1ex}%
{\titlerule[2pt]}]
\begin{document}
\chapter{The real numbers}
\end{document}
lockstep
- 250,273
titlesec– Seamus Feb 18 '11 at 17:53