software

Formatting chapters in LaTeX

1 min read

If you need to change the chapter formatting in a LaTeX document, you can use the titlesec package (https://ctan.org/pkg/titlesec?lang=en)

For example, to change the chapter so that it shows the chapter number followed by its name, follow these steps:

Declare that we want to use the titlesec package

text
\usepackage{titlesec}

Then we define the formatting we want. In this case, we want the chapter number to appear, followed by “.” and the chapter name (separated by a space), all on the same line.

To achieve this, we place the following code before the start of the document (set by \begin{document}):

text
\titleformat{\chapter}[hang]
	{\normalfont\Large\bfseries}{\thechapter.\ }{0em}{\Large}

The [hang] option makes the chapter number and the title appear on the same line

In this configuration, {0em} sets the spacing between the chapter number and its title

An example of the result when the chapter is started in the document with the command \chapter{Âmbito}:

In the package repository you can look at its code and other information about it. At the time of writing, the repository URL is:

https://github.com/jbezos/titlesec

#latex