Designing Pages
local graph
Chapter 3 — Designing Pages
Section titled “Chapter 3 — Designing Pages”Now that you know how to format text, it’s time to look at entire pages and the overall document structure.
In this chapter, we’ll structure a document using chapters and sections, and learn how to adjust its page layout, including margins, page orientation, headers, and footers. This gives you control over the entire document design.
We’ll cover the following topics:
- Structuring with chapters
- Adjusting page margins
- Creating a two-column layout
- Designing headers and footers
- Adding footnotes
- Handling page breaks
- Enlarging a page
- Changing line spacing
- Aligning the text area height
- Creating a table of contents
Working through these will build a better understanding of document classes and packages.
We’ll start with a multi-page example document that we’ll keep using throughout the chapters to try out new features. You can view, edit, and compile all examples online at the book’s companion website: https://latexguide.org/chapter-03.
Structuring with chapters
Section titled “Structuring with chapters”Let’s begin writing a longer document. We’ll select the book document class and fill the pages with placeholder text to explore the page layout:
- Create a new document, and enter the following lines as our preamble:
\documentclass[a4paper,12pt]{book}\usepackage[english]{babel}\usepackage{blindtext}
- Proceed with writing the document body containing a chapter heading, section and subsection headings, and some filler text:
\begin{document}\chapter{Exploring the page layout}In this chapter we will study the layout of pages.\section{Some filler text}\blindtext\section{A lot more filler text}More dummy text will follow.\subsection{Plenty of filler text}\blindtext[10]\end{document}
- Compile it by clicking on Typeset. Look at the first page:

Figure 3.1 – An example page
Figure 3.1 – An example page
We have chosen the book document class. This class is suitable for extensive documents such as a book, a scientific report, or a thesis, when it’s printed two-sided. Books are commonly two-sided and consist of chapters. By default, and this is very common, chapters start on right-hand pages, which have odd page numbers. If necessary, LaTeX inserts a blank, left-hand, even-numbered page so that the next chapter can begin on the following right-hand page.
Furthermore, books often have front matter, which includes one or more title pages, and back matter, which typically consists of a bibliography, index, and other relevant content. The book class supports all of this.
We used the a4paper option so the document would be formatted to fit on A4 paper. For the US letter paper size, we would use the letterpaper option instead. The document class 12pt option instructed LaTeX to use a base font size of 12pt.
We loaded the babel package. That package provides typographic support tools for many languages, including proper hyphenation rules for the chosen language and translations for implicit terms. For example, we used the english option with babel and got Chapter 1 in our chapter heading. If we choose french instead of english, we will get Chapitre 1 in our heading.
American English is the default. For British English, we would use the british option with babel. There are very small differences between the two. In British English, some words are spelled differently, and hyphenation rules are a bit different, for example.
We loaded the blindtext package, which has been developed to produce filler text. It uses babel to detect the language of the document; we stated the english language to babel, which actually means American English. Without babel, blindtext would use Latin filler text by default. Then, the \blindtext command prints some dummy text just to fill the space.
The \chapter command produced a large heading, which will always begin on a new page. We’ve already seen the \section command. It’s our second sectioning level and generates a smaller heading than \chapter. The numbering of this heading is automatically updated by LaTeX. Lastly, we refined the sectioning with the \subsection command followed by more dummy text to fill up the page.
Another widely used package for dummy text is called lipsum. It generates the famous Lorem Ipsum text that typesetters have used for decades.
Let’s now look at how to adjust the default margins.
Adjusting page margins
Section titled “Adjusting page margins”Sometimes, publishers or supervisors request that you follow their specifications for a document. Apart from font size, interline spacing, and other style issues, there may be specifications for the margins. In this case, you would need to override LaTeX’s defaults, specifying the margins precisely.
The geometry package makes that easy. We’ll load the geometry package and state the exact width and height of all margins:
- Extend the preamble of the previous example in this chapter with this command:
\usepackage[a4paper, inner=1.5cm, outer=3cm, top=2cm, bottom=3cm,bindingoffset=0.5cm]{geometry}
- Click Typeset to compile the code and observe how the margins change.
The geometry package handles the layout, including paper size, margins, and other dimensions. We chose the A4 paper size, with an outer margin of 3 cm and an inner margin of 1.5 cm.
When a two-sided book lies open in front of us, the two inner margins visually merge into a single central space. To achieve visually balanced margins—left, center, and right—we can set the inner margin to half the width of the outer margin. That’s why outer margins are typically wider than inner margins. There may be a reason to make the inner margin slightly wider; we might lose this space later due to binding methods such as gluing or stapling. But this depends on the kind of binding, and then it’s done with an extra bindingoffset option.
We set the top margin to 2 cm and the bottom margin to 3 cm. Lastly, we specified a value of 0.5 cm for a binding correction.
In the early days of LaTeX, it was common to manipulate the layout dimensions directly. This approach had some disadvantages. We could easily make mistakes in calculating the lengths, for instance, the left margin plus the right margin plus the text width might not fit the paper width.
The geometry package simplifies this process. It provides an easy-to-use interface for layout settings. It provides auto-completion, calculates missing values to match the paper size, and even adds missing lengths using a heuristic approach to achieve a well-balanced layout.
The geometry package understands options as "key=value" pairs, separated by commas. If you load geometry without any arguments, you can set those arguments later with the \geometry{argument list} command.
Let’s take a closer look at such geometry package options to control every aspect of your page layout.
Choosing the paper size
Section titled “Choosing the paper size”The geometry package offers various options for setting paper size and orientation:
paper=namesets the paper size by name, for example,paper=a4paper. Supported sizes includeletterpaper,executivepaper,legalpaper,a0paper,a6paper,b0paper,b6paper, and others.paperwidthandpaperheightset custom paper dimensions, such aspaperwidth=7inandpaperheight=10in.papersize={width,height}sets both the width and height of the paper in one key, such aspapersize={7in,10in}. This is an example of a double-valued argument.portraitsets the paper orientation to portrait mode, which is the default option.landscapeswitches the paper orientation to landscape mode.
If you have already specified the paper name in the document class, geometry will pick that up automatically. In fact, all document class options are passed to the packages that support them.
Specifying the text area
Section titled “Specifying the text area”Use these options to control the size of the text block:
textwidthsets the width of the main text area, such astextwidth=140mmtextheightsets its height, such astextheight=180mmlinesoffer an alternative way to define the text height by specifying the number of lines, such aslines=25includeheadincludes the page header in the text height calculation; this option is set tofalseby defaultincludefootincludes the footer of the page in the text area; this option is also set tofalseby default
Setting the margins
Section titled “Setting the margins”You can control the visible margins using the following options:
leftandrightdefine the width of the left and right margins, such asleft=2cm. Use these for one-sided documents.innerandouterset the width of the inner and the outer margin, such asinner=2cm. Use them for two-sided documents.topandbottomset the height of the vertical margins, such astop=25mm.twosideenables two-sided layout mode. This means that the left and right margins will be swapped on left-hand pages, also called verso pages.- If your book is printed and bound, whether by glue, staples, or other means, the binding may cover part of the inner margin. You can set a value to the
bindingoffsetoption to reserve width to compensate for the part of the inner margin that’s hidden in the binding, so the visible inner margin looks as wide as you expect.
That’s just a selection of commonly used options—there are many more. You can choose and set some options intuitively—for instance, \usepackage[margin=3cm]{geometry} will result in a 3 cm margin on each edge of the paper, and the paper size comes from the document class, unless specified otherwise.
The auto-completion works like this:
paperwidth = left + width + right, wherewidth=textwidthby defaultpaperheight = top + height + bottom, whereheight=textheightby default
If you decide to include marginal notes within the text body when calculating the layout, the width could get wider than textwidth. If two dimensions of the right side of each formula are given, the missing dimension will be calculated. That’s why it may be enough to specify left and right, and top and bottom, respectively. Even if just one margin is specified, the other dimensions will be determined using default margin ratios, as follows:
top:bottom=2:3left:right=1:1for one-sided documentsinner:outer=2:3for two-sided documents
It might sound complex, but that’s just how geometry helps you achieve a clean, balanced page layout, even when some values are missing.
The geometry package comes with a comprehensive manual. Don’t let its length intimidate you; it’s designed to guide you through the many features.
As shown earlier in Chapter 1, Getting Started with LaTeX, you can open the manual by typing texdoc geometry at the command line, a terminal window, or on the internet at https://texdoc.org/pkg/geometry.
Now that you know how to set up the basic page geometry, we’ll move on to options for changing the text layout, such as landscape orientation and multi-column formatting.
Creating a two-column layout
Section titled “Creating a two-column layout”You already know that a document class defines the foundation of your document. It provides commands and environments extending the LaTeX standard features. Though the class provides a default style, you can customize it using document class options.
Let’s switch the orientation of our first example to landscape, and typeset our text in two columns:
- Add the
landscapeandtwocolumnoptions to the\documentclassline of our example, as follows:\documentclass[a4paper,12pt,landscape,twocolumn]{book} - Load the
geometrypackage:\usepackage{geometry} - Click Typeset to compile, and see the new layout in effect:

Figure 3.2 – A landscape two-column page layout
Figure 3.2 – A landscape two-column page layout
By using the landscape option, we switched the page orientation from portrait to landscape. The twocolumn option splits the document body text into two columns.
We loaded the geometry package to ensure that the PDF page matches the landscape layout. Without it, the final PDF would remain in portrait mode.
The \twocolumn[opening text] command starts a two-column page with optional opening text over the full width. \onecolumn begins a one-column page. If you’d like to balance the columns on the last page or if you wish to have more than two columns, use the multicols package.
The LaTeX base classes are article, book, report, slides, and letter. As the name suggests, the last one can be used to write letters, though there are further suitable classes, such as scrlttr2.
slides can be used to create presentations, but today there are more powerful and feature-rich classes, such as beamer and powerdot.
Let’s sum up the options of the base classes:
a4paper,a5paper,b5paper,letterpaper,legalpaper, orexecutivepaper: The output will be formatted according to this paper size; for example, A4 will be formatted as 210 mm x 297 mm. Theletterpaperoption (8.5 in x 11 in) is the default. Loading thegeometrypackage allows for more sizes.10pt,11pt, or12pt: The size of normal text in the document; the default is 10 points (10pt). The size of headings, footnotes, indexes, and so on, will be scaled accordingly.landscape: Switches to landscape format by swapping the width and height of the output paper dimensions.onecolumnortwocolumn: Decides whether the pages will be one-column (default) or two-column. Theletterclass doesn’t support it.onesideortwoside: Controls layout for printing on one side or both sides of a page.onesideis the default, except for thebookclass.twosideis not applicable to theslidesclass and theletterclass.openrightoropenany: The first option lets chapters begin on a right-hand page (the default for thebookclass), while the second option permits chapters to start on any page (the default for thereportclass). These options are only supported by thebookandreportclasses because the other classes don’t provide chapters.titlepageornotitlepage: The first causes a separate title page when\maketitleis used and is the default, except for thearticleclass. The default ofarticleisnotitlepage, which means that normal text may follow the title on the same page.finalordraft: Ifdraftis set, then LaTeX will mark overfull lines with a black box, which is helpful for reviewing and improving the output. Some packages support these options as well, behaving differently then, such as omitting the embedding of graphics and listings when a draft has been chosen.finalis the default.openbib: When this option is set, a bibliography will be formatted in open style instead of compressed style.fleqn: This left-aligns displayed formulas instead of centering.leqno: For numbered displayed formulas, the number will be put on the left side. The right side is the default.
Many other classes support these options as well, and often offer even more. For an uncommon base font size, the extarticle, extbook, extreport, and extletter classes provide base font sizes from 8 points to 20 points. The KOMA-Script classes support arbitrary base font sizes.
KOMA-Script classes serve as enhanced alternatives to the base classes: for each base class, such as article, book, or report, there’s a corresponding KOMA class (scrartcl, scrbook, and scrreprt, respectively). They offer a significantly expanded feature set, with many additional commands and options for customizing document layout and behavior. Visit https://texdoc.org/pkg/koma-script to consult the manual.
As page headers have been mentioned, let’s explore them now.
Designing headers and footers
Section titled “Designing headers and footers”When we tested the initial version of our example, you may have noticed that, except on the chapter’s first page, all other pages displayed the page number, chapter title, and section title in their headers. So, in our two-sided layout, on page 2, in a left-hand page header, the page number is in the outer margin—here, on the left side:

Figure 3.3 – The header of page 2
Figure 3.3 – The header of page 2
By contrast, this is how our right-hand page header on page 3 looks, with the page number in the outer margin, which is on the right side now:

Figure 3.4 – The header of page 3
Figure 3.4 – The header of page 3
In a one-sided layout, there would be no such difference in the header layout; it would follow a uniform style. The headers in a one-sided layout are as in Figure 3.4. By default, heading text is on the left side, and the page number is on the right side.
Although these standard headers are already quite suitable, we can further customize them to suit our preferences better.
The default shape of the page headings is slanted. Furthermore, they are written in capital letters. We shall use bold typeface instead, and we will use a small-caps font for the chapter title. We will load the fancyhdr package and use its commands to achieve that:
- Load the first example of this chapter.
- Insert the highlighted lines to get this:
\documentclass[a4paper,12pt]{book}\usepackage[english]{babel}\usepackage{blindtext}\usepackage{fancyhdr}\fancyhf{}\fancyhead[LE]{\scshape\nouppercase{\leftmark}}\fancyhead[RO]{\nouppercase{\rightmark}}\fancyfoot[LE,RO]{\thepage}\pagestyle{fancy}\begin{document}\chapter{Exploring the page layout}In this chapter we will study the layout of pages.\section{Some filler text}\blindtext\section{A lot more filler text}More dummy text will follow.\subsection{Plenty of filler text}\blindtext[10]\end{document}
- Compile the code. The footers will contain the page number on their outer side.
A right-hand page header now looks like the following:

Figure 3.5 – The new header of page 2
Figure 3.5 – The new header of page 2
A left-hand header now looks like this:

Figure 3.6 – The new header of page 3
Figure 3.6 – The new header of page 3
We used the fancyhdr package to customize the headers and footers of our document. The package command names start with \fancy. Our first action was calling \fancyhf{}; this command clears the headers and footers. Furthermore, we used the following commands:
\leftmark: Stores the chapter title together with the chapter number. Capital letters are used as the default.\rightmark: Stores the section title together with its number. Capital letters are used as well.\nouppercase: This command prevents the automatic capitalization in its argument.\scshape: We switched to a small-caps font.
We used the \fancyhead command with the optional LE argument to place the chapter title in the header. LE stands for left-even and means that this chapter title will be put on the left side of the header on even-numbered pages.
Conversely, we called the \fancyhead command with RO to put the section title into the header. RO stands for right-odd and means that this section heading shall be displayed on the right side of the header on odd-numbered pages.
Afterward, we used \fancyfoot to display the page number in the footer. This time, we used LE and RO, which showed the page number on both even and odd pages, always on the outer side. Then, the \thepage command prints the page number.
All these commands are used to modify a page style provided by fancyhdr; this style is called fancy. We had to instruct LaTeX to use this style, and we did so through the \pagestyle{fancy} command.
Emphasizing by writing all letters capitalized, as fancyhdr does by default, is called all caps. It is widely regarded as a questionable style. That’s why we moved to small caps.
There are different styles of headers and footers. That combination is referred to as a page style. Let’s see what page styles are available.
Understanding page styles
Section titled “Understanding page styles”LaTeX and its base classes offer four built-in page styles:
empty: Neither a header nor a footer is shown.plain: No header. The page number will be printed and centered in the footer.headings: The header contains titles of chapters, sections, and/or subsections, depending on the class, as well as the page number. The footer remains empty.myheadings: The header contains user-defined text and the page number; the footer is empty.
The fancyhdr package introduces a powerful page style called fancy, which enables users to customize both the header and the footer.
The following two commands may be used to choose the page style:
\pagestyle{name}: Switches to the page style name from this point onward\thispagestyle{name}: Applies thenamepage style only to the current page; subsequent pages will retain the style used previously
You have noticed that the page style changes where a chapter begins, differing from the style of other pages. Such pages will have a plain style. If you think all pages should use the same style, consider some books: it’s very common for chapter beginnings to differ in style. They usually have a blank header. The \thispagestyle command can be used to override that.
We can modify content and positioning in headers and footers, as we will see next.
Customizing headers and footers
Section titled “Customizing headers and footers”LaTeX divides both headers and footers into three pieces: left, center, and right (l, c, and r, respectively). You can customize each part using the following commands:
- For the header:
\lhead,\chead, or\rhead - For the footer:
\lfoot,\cfoot, or\rfoot
Each of these commands requires a mandatory argument, such as \chead{User's guide} or \cfoot{\thepage}. This argument will be put into the corresponding area of the page.
Alternatively, you could use these versatile commands:
- Header:
\fancyhead[code]{text} - Footer:
\fancyfoot[code]{text}
Here, code may consist of one or more letters:
L: LeftC: CenterR: RightE: Even pageO: Odd page
It doesn’t matter if we choose uppercase or lowercase letters. We already used such combinations in our example.
Another customization is modifying the separation line between the text and the footer, up next.
Using decorative lines in headers or footers
Section titled “Using decorative lines in headers or footers”We can add and adjust lines between the header and the body text, and the body text and the footer, respectively, with these two commands:
\renewcommand{\headrulewidth}{width}\renewcommand{\footrulewidth}{width}
Here, width may be a value such as 1pt, 0.5mm, and so on. The default is 0.4pt for the header line and 0pt for the footer line. 0pt means that a line is not visible.
While \newcommand defines a new command, \renewcommand redefines an existing command. Incidentally, we’ve got to know a new concept: a lot of LaTeX commands may be redefined in this way. This can be simply changing a value, as here, or redefining the code for a command.
Changing LaTeX’s header marks
Section titled “Changing LaTeX’s header marks”As we already know, LaTeX classes and packages automatically store sectioning numbers and headings in the \leftmark and \rightmark macros. It will be done when we call \chapter, \section, or \subsection. So, we could just use \leftmark and \rightmark in the arguments of the fancyhdr commands.
We may sometimes need to manually update those entries, even if we rely on this automation. For instance, the starred sectioning commands such as \chapter* and \section* won’t produce a header entry, as indicated earlier. In such a case, two commands will help us:
\markright{right head}sets the right heading\markboth{left head}{right head}sets both the left and right headings
The default headings style is easy to use and gives good results. myheadings can be used together with \markright and \markboth. However, the most flexible way is given by fancyhdr, especially in combination with \markright and \markboth.
A very good alternative to fancyhdr is the package called scrpage-scrlayer. It belongs to KOMA-Script, but scrpage-scrlayer works with other classes as well. It provides similar functionality and offers even more features.
The footer is a good place to add notes. Let’s see how to do that in the next section.
Adding footnotes
Section titled “Adding footnotes”As briefly mentioned in Chapter 2, Formatting Text and Creating Macros, LaTeX provides a command to typeset footnotes. Let’s see it in action.
Let’s go back to the very first example of this chapter. We shall insert one footnote in the body text and one in a section heading:
- Modify the example by inserting a footnote, as shown in the highlighted line:
\documentclass[a4paper,12pt]{book}\usepackage[english]{babel}\usepackage{blindtext}\begin{document}\chapter{Exploring the page layout}In this chapter we will study the layout of pages.\section{Some filler text}\blindtext\section{A lot more filler text}More dummy text\footnote{serving as a placeholder}will follow.\subsection{Plenty of filler text}\blindtext[10]\end{document}
- Compile the code to see how the footnote looks in print:

Figure 3.7 – Text with a footnote
Figure 3.7 – Text with a footnote
The \footnote{text} command placed a superscripted number at the current position.
Furthermore, it prints its argument text at the bottom of the page, marked by the same number. As we’ve seen, such notes are separated from the main text by a horizontal line.
\footnote[number]{text} produces a footnote marked by this optional number, an integer. If we don’t give the optional number, an internal counter will be stepped and used. This will be done automatically; we don’t need to worry.
Two additional commands help us selectively put only a footnote mark or text:
\footnotemark[number]produces a superscripted number in the text as a footnote mark. If the optional argument is not given, it also steps and uses the internal footnote counter. No footnote text will be generated.\footnotetext[number]{text}generates footnote text without putting a footnote mark in the text, and it does not step up the internal footnote counter.
Set a footnote command right after the related text. Don’t leave a space in between; otherwise, you would get a gap between the text and the following footnote mark.
In Figure 3.7, we saw a line that separates the footnotes from the text. We will now see how to adjust that line.
Modifying the footnote line
Section titled “Modifying the footnote line”The line that separates footnotes from the text is produced by the \footnoterule command. If we wish to omit that line or modify it, we must redefine it. We learned about \renewcommand earlier, so let’s use it.
We will use \renewcommand to override the default \footnoterule command:
- Take the previous example and add the following lines to the preamble:
\renewcommand{\footnoterule}{\noindent\smash{\rule[3pt]{\textwidth}{0.4pt}}}
- Click on Typeset to compile, and see how the line has changed:

Figure 3.8 – A modified footnote line
Figure 3.8 – A modified footnote line
The existing \footnoterule command will be replaced by the new definition that we wrote in the second line of the first step. The \rule[raising]{width}{height} command draws a line, here 0.4 pt thick, and as wide as the text, raised a bit, by 3 pt. Through the \smash command, we let our line pretend to have a height and depth of zero, so it occupies no vertical space at all. This way, the page balancing will not be affected. You already know \noindent, which avoids the paragraph indentation.
If you want to omit that footnote line completely, you just need to write the following:
\renewcommand{\footnoterule}{}Now, the command is defined to do nothing, and we won’t get a dividing line.
Using packages to expand footnote styles
Section titled “Using packages to expand footnote styles”There are different habits for setting footnotes. Some styles require footnotes numbered per page; they might have to be placed in the document as so-called endnotes, and symbols instead of numbers may be used. More demands exist, and, therefore, several packages have been developed to comply with them. Here’s a selection:
endnotes: Places footnotes at the end of the documentmanyfoot: Allows nested footnotesbigfoot: Replaces and extendsmanyfootand improves page break handling with footnotessavefnmark: Useful when you need to use footnotes several timesfootmisc: An all-round package; introduces numbering per page, is able to save space when many short footnotes are used, offers symbols instead of numbers as footnote marks, and provides hanging indentation and other styles
Have a look at the respective package documentation to learn more using either the texdoc command, as explained in Chapter 1, Getting Started with LaTeX, or at https://texdoc.org.
As we’ve talked about footnotes at the end of a page, let’s see how to enforce ending a page ourselves in case we don’t want to let it automatically happen.
Handling page breaks
Section titled “Handling page breaks”As you’ve seen in our example, LaTeX itself handles the page breaking. There might be occasions where we’d like to insert a page break ourselves before LaTeX does. LaTeX offers several commands to achieve this, with or without vertical balance.
We will now go back to the first version of our example, and we shall manually insert a page break right before subsection 1.2.1:
- Insert the highlighted line into our example, which contains the
\pagebreakcommand:\documentclass[a4paper,12pt]{book}\usepackage[english]{babel}\usepackage{blindtext}\begin{document}\chapter{Exploring the page layout}In this chapter we will study the layout of pages.\section{Some filler text}\blindtext\section{A lot more filler text}More dummy text will follow.\pagebreak\subsection{Plenty of filler text}\blindtext[10]\end{document} - Compile the code and take a look at the result:

Figure 3.9 – A stretched page
Figure 3.9 – A stretched page
- Replace
\pagebreakwith\newpage. - Compile again, and compare:

Figure 3.10 – A non-stretched page
Figure 3.10 – A non-stretched page
At first, we inserted the \pagebreak command; as its name suggests, it causes a page break. Furthermore, the text has been stretched to fill the page down to the bottom. That can be desirable for having the same text height on all pages.
Afterward, due to the obviously unpleasant whitespace between the paragraphs and headings, we replaced \pagebreak with \newpage. This command breaks the page as well, but it doesn’t stretch the text: the remaining space of the page will stay empty.
So, \pagebreak behaves like \linebreak, and \newpage works like \newline (for pages instead of lines). There’s even a \nopagebreak command that’s analogous to \nolinebreak and forbids page breaking. \pagebreak won’t break a line, while \nopagebreak doesn’t refer to the middle of a line; both commands apply at the end of the current line. Of course, they immediately have an effect when used between paragraphs.
If you use the two-column format, both \pagebreak and \newpage will begin on a new column instead of a new page.
There are two further variants: \clearpage works like \newpage, except that it will start on a new page, even in two-column mode. \cleardoublepage does the same but causes the following text to start on a right-hand page, inserting a blank page if necessary. The latter is helpful for two-sided documents.
More importantly, both commands cause all figures and tables that LaTeX has in its memory to be printed out immediately.
\pagebreak and \nopagebreak can take an optional argument that requests a certain line break, as follows. The argument is an integer between 0 and 4. Here, 0 means that a page break is allowed, 1 means it’s desired, 2 and 3 mark more insistent requests so LaTeX tries harder to stretch the text to reach the page bottom, and 4 will enforce a page break. \pagebreak and \nopagebreak are very similar to the \linebreak and \nolinebreak command pair, which we saw in Chapter 2, Formatting Text and Creating Macros.
Such manual page breaks reduce the amount of text that fits on the page. Let’s now examine the opposite: adding more text to a page.
Enlarging a page
Section titled “Enlarging a page”There may be occasions where we want to add a little more text to a page, even if it will be squeezed a bit or the text height increases. There’s a command that will help us out: \enlargethispage.
We’ll modify our example slightly. This time, we will try to avoid a nearly empty page by squeezing the text on the preceding page:
- Remove the
\newpagecommand from our example and switch to an11ptbase font. This time, use less filler text in the subsection:\documentclass[a4paper,11pt]{book}\usepackage[english]{babel}\usepackage{blindtext}\usepackage[a4paper, inner=1.5cm, outer=3cm, top=2cm,bottom=3cm, bindingoffset=1cm]{geometry}\begin{document}\chapter{Exploring the page layout}In this chapter we will study the layout of pages.\section{Some filler text}\blindtext\section{A lot more filler text}More dummy text will follow.\subsection{Plenty of filler text}\blindtext[3]\end{document} - Compile, and the result will consist of two pages. This is the first page:

Figure 3.11 – A fully filled page
Figure 3.11 – A fully filled page
And this is the text on the second page:

Figure 3.12 – Remaining text on the second page
Figure 3.12 – Remaining text on the second page
- Insert this command right after the
\subsectionline:\enlargethispage{\baselineskip} - Compile again, and now our document fits on just one page:

Figure 3.13 – All text fits on a single page
Figure 3.13 – All text fits on a single page
We used the \enlargethispage command to squeeze more text onto a page. This command takes the additionally requested height as its argument. The \baselineskip command returns the height of a text line that we used as the argument. So, LaTeX could put one extra line onto the page, and even the remaining line fitted in as well because LaTeX compressed some whitespace.
We could use factors: write \enlargethispage{2\baselineskip} to get two more lines on a page. It doesn’t even need to be an integer value. As always, when stating a length, you can use other units, such as 10pt, 0.5in, 1cm, or 5mm, and even negative values.
Only the current page will be affected by this command. There’s a starred version: \enlargethispage* would additionally shrink all vertical spaces on the page to their minimum.
However, \enlargethispage should be considered just for a possible easy fix when you quickly need to put more text on a single page. In general, we can adjust the text quantity on the page by changing the margins, as we already know, or by adjusting the line spacing within text. Let’s examine line spacing in the next section.
Changing the line spacing
Section titled “Changing the line spacing”Without some vertical space between the lines, the readability of our text could suffer. Adding such space would help lead the eye along the line. Although LaTeX already ensures good readability by choosing meaningful interline spacing, publishers may require different spacing.
We shall modify the very first example of this chapter by adding half of a line height to the line spacing:
- Extend the preamble of our example with this command:
\usepackage[onehalfspacing]{setspace}
- Compile the code to see the change:

Figure 3.14 – Additional interline spacing
Figure 3.14 – Additional interline spacing
We loaded the setspace package to adjust the line spacing. We provided the onehalfspacing option, which increases the spacing by half of a line height for the whole document.
The setspace package understands three options:
singlespacingis the default. No additional space will be inserted. The text will be typeset with LaTeX’s default interline spacing, which is about 20 percent of the line height.onehalfspacingmeans one-and-a-half spacing, as you can see in our example.doublespacingcan be used for even more spacing; the distance between the baselines of successive text lines would be twice as high as a single line.
In typesetter’s jargon, the distance between the baselines of consecutive text lines is referred to as leading (pronounced “ledding” from the metal “lead,” once used to separate lines).
Now that we adjusted vertical spacing and page breaks, let’s see how to align the text area on the pages vertically.
Aligning the text area height
Section titled “Aligning the text area height”Let’s revisit Figure 3.9. It showed a page where the text appeared stretched: extra vertical space had been inserted between paragraphs and headings. This behavior is typical of the book document class: in two-sided layouts, LaTeX aligns the text block vertically so that facing pages have the same height.
While this balancing is intended to be visually pleasing, it may sometimes lead to awkward spacing, especially if the page contains little text. In such cases, you might prefer to disable this alignment.
LaTeX offers two commands to control vertical text alignment:
\raggedbottomdisables vertical alignment, so you get less stretching and natural page height\flushbottomenforces equal text height on every page, so LaTeX stretches the content if necessary
These commands are usually placed in the preamble for a consistent layout across the document. However, they can also be used selectively within the document to switch styles when needed.
Here’s a practical guideline:
- Use
\flushbottomfor text-rich, two-sided documents such as books for a perfect visual appearance when the book is opened. That’s the default with thebookclass. - Use
\raggedbottomwhen your content varies in density, such as when you have many figures and tables and notice unwanted spacing. That’s the default in one-sided document classes such asarticle,report,letter, andpresentationclasses.
Now that we have finished designing the entire document, let’s add a table of contents.
Creating a table of contents
Section titled “Creating a table of contents”A book commonly begins with a table of contents, so let’s create one based on our numbered headings:
- In our previous document, let’s remove the
landscapeandtwocolumnoptions. - Remove the
setspacepackage, that is, delete this line:\usepackage[onehalfspacing]{setspace} - Add the
\tableofcontentscommand right after\begin{document}.
Our code shall now look like this:
\documentclass[a4paper,12pt]{book}\usepackage[english]{babel}\usepackage{blindtext}\usepackage[a4paper, inner=1.5cm, outer=3cm, top=2cm,bottom=3cm, bindingoffset=1cm]{geometry}\begin{document}\tableofcontents\chapter{Exploring the page layout}In this chapter we will study the layout of pages.\section{Some filler text}\blindtext\section{A lot more filler text}More dummy text will follow.\subsection{Plenty of filler text}\blindtext[10]\end{document}- Compile the code twice. Afterward, the first page of your output will contain this table:

Figure 3.15 – Table of contents
Figure 3.15 – Table of contents
The \tableofcontents command tells LaTeX to produce and print a table of contents. During a typesetting run, LaTeX writes the headings into an auxiliary file with the .toc filename extension. The \tableofcontents command reads that .toc file in for printing the table of contents.
The LaTeX typesetting process is linear; it runs from the start to the end of the code. The \tableofcontents command comes at the beginning, and the headings come later. That’s why we had to typeset twice:
- In the first run,
\tableofcontentsdid not know any headings, and the table of contents stayed empty. While continuing to run, LaTeX put the headings into the.tocfile. - In the second run,
\tableofcontentsfound and read the.tocfile to print the contents.
It’s good to keep that in mind for later: when you change a heading and compile the document, you can see the change in the text. But the table of contents will get this change in the next compiler run.
The sectioning commands create the table of contents entries. We used \chapter, \section, and \subsection, and we’ve got an entry for each.
A heading might be very long; it could span two or more lines. In that case, we might wish to shorten its corresponding table of contents entry. Let’s see how.
We can use the optional arguments of the section commands to produce shorter entries, different from the actual headings. Let’s edit the example shown in Figure 3.15 by inserting shorter titles in square brackets:
\chapter[Page layout]{Exploring the page layout}\section[Filler text]{Some filler text}\section[More]{A lot more filler text}\subsection[Plenty]{Plenty of filler text}Compile the example twice. You will see that the headings stay the same, but the table of contents has changed:

Figure 3.16 – Shortened table of contents entries
Figure 3.16 – Shortened table of contents entries
Besides the mandatory argument producing the heading, each sectioning command understands an optional argument. If an optional argument is given, it will be used instead of the mandatory heading for the contents table entry.
In Chapter 8, Managing Contents, Indexes, and Bibliography we shall take a further look at this and learn how to customize the table of contents further. Let’s review the sectioning commands for the book, report, and article classes again. There are seven levels in those base classes:
\part: This is for dividing the document into major units. The numbering of other sectional units is independent of\part. A part heading will use a whole page inbookandreportdocuments.\chapter: This gives a large heading that will start at a new page, available in thebookclass and in thereportclass.\section,\subsection, and\subsubsection: These give bold headings, and they are available in all three classes.\paragraphand\subparagraph: Also available in all three classes, they produce a run-in heading. That means the heading runs straight into the text; there’s no line break between the heading and the following text. Also, it’s a sectioning command, and should not be confused with common text paragraphs.
Except \part, all sectioning commands reset the counter of the section that’s one level below in the hierarchy. For instance, \chapter resets the section counter. This way, the sections will be numbered per chapter.
To sum up, such sectioning commands are easy to use, and they do a lot:
\partand\chaptercause a page break before the heading- All generate a number and a presentation for it, some depending on the higher-level counters (for example, Section 1 of Chapter 2 would generate
2.1) - Except
\part, they reset the counter of the next-level sectional unit so that the lower-level unit will start with1 - They produce a table of contents entry
- They format the heading, usually in bold, and the larger it is, the higher it is in the hierarchy
- They save headings internally for using them in a page header
All sectioning commands provide a starred form, as follows:
\section*{title}If you use this form, the numbering will be suppressed, and there won’t be an entry in the table of contents or in a header. Look at the Contents heading in our example; this has actually been typeset by \chapter* inside the \tableofcontents macro.
Summary
Section titled “Summary”In this chapter, we worked out how to design the overall layout of a document.
Specifically, we covered choosing page dimensions, margins, and orientation. We know how to switch to a two-column layout and how to adjust line spacing. Furthermore, we can now customize headers and footers, add footnotes, and include a table of contents in our document.
Beyond layout, we covered some general topics, such as changing document properties by selecting document class options and package options, as well as redefining existing commands.
Now that we’ve established the foundation, it’s time to structure the content itself. In the next chapter, we´ll learn how to create lists to present information in a clear and organized way.