Using the document class book, chapters headings (Chaper 1) are aligned on the left. How to center them?
1 Answer
Using the titlesec
package you can say:
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries\centering}{\chaptertitlename\ \thechapter}{20pt}{\Huge}
if both the heading and the title are to be centered, or
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\centering\chaptertitlename\ \thechapter}{20pt}{\Huge}
if only the heading must be centered.
If both the heading and the title are to be centered, the sectsty
package provides another easy solution:
\documentclass{book}
\usepackage{sectsty}
\chapterfont{\centering}
\begin{document}
\chapter{Test chapter}
\end{document}
If, for some reason, no additional packages are to be used, the a redefinition of \@makechapterhead
(for numbered chapters) and of \@makeschapterhead
(for unnumbered chapters) will be needed (the original definitions for both commands can be found in book.cls
):
\documentclass{book}
\makeatletter
\def\@makechapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \centering\normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\huge\bfseries \@chapapp\space \thechapter
\par\nobreak
\vskip 20\p@
\fi
\fi
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
\def\@makeschapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \centering
\normalfont
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
\makeatother
\begin{document}
\chapter{Test chapter}
\end{document}