1. Introduction

In this tutorial, we’ll study how to center the title of a chapter in a LaTeX document.

2. Chapters, Sections, and Subsections

A document in LaTeX is organized into different components. In hierarchical order, these are the chapters, the sections, and the subsections:

chapters sections subsections

In LaTeX, the most common document classes that typically contain all three of these components include the “report” and the “book”; the document class “article”, since we use it predominantly for papers under ten pages, tends to miss one or more of those parts.

For this tutorial, we assume that we’re writing a report comprising chapters, sections, and subsections. We want to center the title of each chapter but not the title for any other part of the report.

The code snippet we’ll work with is this:

\documentclass{report}

\begin{document}

\chapter{This is the title of the chapter}

\section{A new section}

\subsection{The first subsection in the first section in the first chapter}
This is the very first paragraph of the report.

\subsection{The second subsection}
This is a second subsection in the same section. 

\section{The section strikes back}
Another paragraph.

\section{Return of the section}
And one more paragraph.
\end{document}

If we copy-paste the snippet into a LaTeX editor such as Lyx or Overleaf and then compile it, we get this result:

LaTex editor snippet

3. Centering Titles Natively

As we can see, by default, the title of the chapter isn’t centered, but rather, it’s aligned to the left of the page. If we want to align the font centrally, we can however treat the text of the title like we would any other string in a LaTeX document: in particular, we can precede it with an alignment command such as \centering, which will then obtain the desired effect.

\documentclass{report}

\begin{document}

\chapter{\centering This is the title of the chapter}

...

\end{document}

After compiling, we can see that the title of the chapter is now centered:

centered chapter title

Notice, however, that if we have multiple chapters in a document, we have to apply this command manually to each of them. This makes us more likely to miss some; and also, it makes it harder to apply changes to the formatting style of the document since we have to review each chapter manually.

4. Centering Titles With a Specialized Package

There are also other options we can use to center titles, by resorting to a LaTeX package that specializes in the formatting of sections. These packages help us because we can then set the formatting style once and for all and automatically apply it to all subsequent chapters. They also help us implement formatting changes more easily because we don’t need to modify each heading where the style needs to be changed.

The simplest package to use is “sectsty” (contraction of section style), which allows us to perform the centering of the chapter’s title with one single command, \chapterfont{\centering}.

To use it, we import the package and apply that command in the preamble of the document:

\documentclass{report}

\usepackage{sectsty}
\chapterfont{\centering}

\begin{document}

...

\end{document}

This is the result:

 

command in document preamble

As we can see, the chapter’s title was correctly centered, while all other headings were left untouched. Notice, however, that in this case, the \centering command was applied to the whole header, including the string “Chapter 1”, which is something that we may or may not like. If we prefer to keep the chapter number aligned to the left, we can replace the \chapterfont command with the \chaptertitlefont:

chaptertitlefont

This obtains the expected result. If we need to modify sections or subsections instead of chapters, alternative commands exist for those parts too. Specifically:

  • \sectionfont;
  • \subsectionfont;
  • \allsectionfont, which includes all of the chapters, sections, and subsections.

Like \chapterfont, these commands have to be inserted in the preamble, and the argument \centering must be passed to them.

5. Conclusions

In this article, we studied how to center titles in LaTeX by using the default functions and the specialized package sectsty.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.