3
The Document

3.1 The Document Class

It is time to describe how an entire document with chapters and sections and other additional content can be produced with LaTeX. We have seen previously, that all LaTeX files should begin by specifying the kind of document to be produced, using the command \documentclass{...}.

We’ve also noted that for a short article 1 1 Short can be misleading as the document can actually turn out to be quite long. we write \documentclass{article}, and for books, we write \documentclass{book}. There are, of course, other document classes available in LaTeX such as report and letter. All of them share some common features and there are features specific to each.

In addition to specifying the type of document, 2 2 which we must do, since LaTeX has no default document class we can also specify some options which modify the default format.

Therefore the actual syntax of the \documentclass command is:

latex
\documentclass[options]{class}

Note that options are given in square brackets and not braces. Options are specified within square brackets ([...]), after which mandatory arguments are given within braces ({...}).

3.1.1 Font Size

We can select the size of the font for the normal text in the entire document with one of the options:

text
10pt 11pt 12pt

Therefore, if we wanted to have a document with size 11pt, we write:

latex
\documentclass[11pt]{article}

The default is 10pt and so this is the size we get, if we do NOT specify any font-size option.

3.1.2 Paper Size

We know that LaTeX has its own method of breaking lines to make paragraphs, which we looked previously. It also has methods to make vertical breaks to produce different pages of output. For these breaks to work properly, it must know the width and height of the paper used. The various options for selecting the paper size are given below: 3 3 As you can see, the measurements are given in inches instead of centimetres. This is because the software was designed in America. However, there are packages and document classes for use with European standards, which we will have a look at it later.

Document Dimensions (in) Document Dimensions (in)
letterpaper 11 × 8.5 a4paper 11 × 8.5
legalpaper 14 × 8.5 a5paper 11 × 8.5
executivepaper 10.5 × 7.25 b5paper 11 × 8.5
Table 3.1: A short-list of possible document classes for the standard documentclass.

Normally, the longer dimension is the vertical one-that is, the height of the page. The default is letterpaper.

The default option abides by the American standards. To use a European standard, you need to declare a4paper in the documentclass options such as:

\documentclass[]{a4paper}

3.1.3 Page Formats

There are options for setting the contents of each page in a single column or in two (2) columns. 4 4 as in most dictionaries and journal publications. This is set by the options

text
onecolumn twocolumn

and the default is onecolumn.

There is also an option to specify whether the document will be finally printed on just one side of each paper or on both sides. The names of the options are:

text
oneside twoside

One of the differences is, with the twoside option, page numbers are printed on the right on odd-numbered pages and on the left on even numbered pages, so when these printed back to back, the numbers are always on the outside, for better visibility and conform to typographical traditions.

LaTeX has no control over the actual printing. It only makes the format for printing.

The default is oneside for article, report and letter and twoside for book.

In the report and book class there is a provision to specify the different chapters. Chapters always begin on a new page, leaving blank space in the previous page, if necessary. With the book class there is the additional restriction that chapters begin only on odd-numbered pages, leaving an entire page blank, if need be.

Such behaviour is controlled by the options,

text
openany openright

The default is openany for reportclass so that chapters begin on “any” new page and openright for the book class so that chapters begin only on new right, that is, odd numbered, page.

There is also a provision in LaTeX for formatting the “title” (the name of the document, author(s) and so on) of a document with special typographic consideration. In the article class, this part of the document is printed along with the text following on the first page, while for report and book, a separate title page is printed. These are set by the options:

text
notitlepage titlepage

As noted above, the default is notitlepage for article and titlepage for report and book. As with the other options, the default behaviour can be overruled by explicitly specifying an option with the document class command.

3.2 Page Style

Having decided on the overall appearance of the document through the \documentclass command with its various options, we next see how we can set the style for the individual pages. In LaTeX, each page has a head and foot usually containing such information as the current page number or the current chapter or section. Just what goes where is set by the command:

latex
\pagestyle{...}

where the mandatory argument can be any one of the following styles :

text
plain empty headings myheadings

The behaviour pertaining to each option is as follows:

plain

The page head is empty and the foot contains just the page number, centred with respect to the width of the text. This is the default for the article class if no \pagestyle is specified in the preamble.

empty

Both the head and foot are empty. In particular, no page numbers are printed.

headings

This is the default for the book class. The foot is empty and the head contains the page number and names of the chapter section or subsection, depending on the document class and its options as given below:

Class Option Left Page Right Page
book, report one-sided - chapter
two-sided chapter section
article one-sided - section
two-sided section subsection
Table 3.2: The behaviour of the headings option.
myheadings

The same as headings, except that the section information in the head are NOT predetermined, but to be given explicitly using the commands \markright or \markboth as described below.

Moreover, we can customise the style for the current page only using the command:

latex
\thispagestyle{style}

where style is the name of one of the styles above. For example, the page number may be suppressed for the current page alone by the command \thispagestyle{empty}. Note that only the printing of the page number is suppressed. The next page will be numbered with the next number and so on.

3.2.1 Heading Declarations

As mentioned previously, in the page style myheadings, we have to specify the text to appear on the head of every page. It is done with one of the commands

latex
\markboth{left head}{right head} \markright{right head}

where left head is the text to appear in the head on left-hand pages and right head is the text to appear on the right-hand pages. The \markboth command is used with the twoside option with even numbered pages considered to be on the left and odd numbered pages on the right. With oneside option, all pages are considered to be right-handed and so in this case, the command \markright can be used.

These commands can also be used to override the default head set by the headings style.

These give only a limited control over the head and foot, since the general format, including the font used and the placement of the page number, is fixed by LaTeX. Better customisation of the head and foot are offered by the package fancyhdr , which is included in most LaTeX distributions.

3.3 Page Numbering

The style of page numbers can be specified by the command:

latex
\pagenumbering{...}

The possible arguments to this command and the resulting style of the numbers are given below:

Command Description
arabic Indo-Arabic numerals
roman lowercase Roman numerals
Roman upper-case Roman numerals
alph lowercase English letters
Alph uppercase English Letters
Table 3.3: Different number styles.

The default value is arabic.

This command resets the page counter . Therefore for example, to number all the pages in the Preface 5 5 an introduction to a book, typically stating its subject, scope, or aims. with lowercase Roman numerals and the rest of the document with Indo-Arabic numerals, declare \pagenumbering{roman} at the beginning of the Preface and issue the command \pagestyle{arabic} immediately after the first \chapter command.

We can make the pages start with any number we want by the command

latex
\setcounter{page}{number}

where number is the page number we wish the current page to have.

3.4 Formatting Lengths

Each page that LaTeX produces consists not only of a head and foot as discussed above but also a body containing the actual text. In formatting a page, LaTeX uses the width and heights of these parts of the page and various other lengths such as the left and right margins. The values of these lengths are set by the paper size options and the page format and style commands.

For example, the page layout with values of these lengths for an odd page and even in this book are separately shown below. These lengths can all be changed with the command \setlength. For example,

latex
\setlength{\textwidth}{15cm}

makes the width of text 15 cm. The package geometry gives easier interfaces to customise page format.

3.5 Parts of a Document

We now turn our attention to the contents of the document itself. Documents are divided into chapters, sections and so on. There may be a title part 6 6 sometimes even a separate title page. and an abstract. All these require special typographic considerations and LaTeX has a number of features which automate this task.

3.5.1 The Title

The “title” part of a document usually consists of the name of the document, the name of author(s) and sometimes a date. To produce a title, we make use of the commands:

latex
\title{document name} \author{author names} \date{date text} \maketitle

Note that after specifying the arguments of \title, \author and \date, we must issue the command \maketitle for this part to be typeset. By default, all entries produced by these commands are centred on the lines in which they appear. If a title text is too long to fit in one line, it will be broken automatically. However, we can choose the break points with the \\ command.

If there are several authors and their names are separated by the \and command, then the names appear side by side. Therefore we can do the following:

latex
\title{Title} \author{Author 1\\ Address line 11\\ Address line 12\\ Address line 13 \and Author 2\\ Address line 21\\ Address line 22\\ Address line 23} \date{Month Date, Year}

If instead of \and, we use (plain old) \\, the names are printed one below another. We may leave some of these arguments empty; for example, the command \date{ } prints no date. Note, however, that if you simply omit the \date command itself, the current date will be printed. The command

latex
\thanks{footnote text}

can be given at any point within the \title, \author or \date. It puts a marker at this point and places the footnote text as a footnote. (The general method of producing a footnote is to type \footnote{footnote text} at the point we want to refer to.) As mentioned earlier, the “title” is printed in a separate page for the document classes book and report and in the first page of the document for the article class. 7 7 this behaviour can be modified by the options titlepage or notitlepage.

3.5.2 Abstract

In the document classes article and report, an abstract of the document in special format can be produced by the commands

latex
\begin{abstract} \end{abstract}

Note that we have to type the abstract ourselves. In the report class this appears on the separate title page and in the article class it appears below the title information on the first page.

This command is NOT available in the book class.

3.5.3 Dividing the Document

A book is usually divided into chapters and, chapters are divided into sections, sections into subsections and so on. LaTeX provides the following hierarchy of sectioning commands in the book and report class:

latex
\chapter \section \subsection \subsubsection \paragraph \subparagraph

Except for \chapter all these are available in article class also. For example, the heading at the beginning of this chapter was produced by

latex
\chapter{The Document}

and the heading of this section was produced by

latex
\section{Dividing the document}

To see the other commands in action, suppose at this point of text let’s type:

latex
\subsection{Example} In this example, we show how subsections and subsubsections are produced (there are no subsubsubsections). Note how the subsections are numbered. \subsubsection{Subexample} Did you note that subsubsections are not numbered? This is so in the \texttt{book} and \texttt{report} classes. In the \texttt{article} class they too have numbers. (Can you figure out why?) \paragraph{Note} Paragraphs and subparagraphs do not have numbers. And they have \textit{run-in} headings. Though named paragraph we can have several paragraphs of text within this. \subparagraph{Subnote} Subparagraphs have an additional indentation too.

which gives us the following output:

3.5.4 Example

In this example, we show how subsections and subsubsections are produced (there are no subsubsubsections). Note how the subsections are numbered.

Subexample

Did you note that subsubsections are not numbered? This is so in the book and report classes. In the article class they too have numbers. (Can you figure out why?)

Note Paragraphs and subparagraphs do not have numbers. And they have run-in headings. Though named ”paragraph” we can have several paragraphs of text within this.

Subnote Subparagraphs have an additional indentation too.

3.5.5 Additional Information

In the book and the report classes, the \chapter command shifts to the beginning of a new page and prints the word Chapter and a number and beneath it, the name we have given in the argument of the command. The \section command produces two (2) numbers 8 8 separated by a dot (i.e., Chapter.2) indicating the chapter number and the section number followed by the name we have given.

It does not produce any text like “Section”.

Subsections have three (3) numbers indicating

the chapter, section and subsection.

\subsubsections and commands below it in the hierarchy do NOT have any numbers. In the article class, \section is highest in the hierarchy and produces single number like \chapter in book. 9 9 It does not produce any text like “Section”, though. In this case, subsubsections also have numbers, but none below have numbers.

Each sectioning command also has a “starred” version which does not produce numbers. Thus \section*{name} has the same effect as \section{name}, but produces no number for this section.

Some books and longish documents are divided into parts also. LaTeX also has a \part command for such documents. In such cases, \part is the highest in the hierarchy, but it does not affect the numbering of the lesser sectioning commands. You may have noted that LaTeX has a specific format for typesetting the section headings, such as the font used, the positioning, the vertical space before and after the heading and so on. All these can be customised but require knowledge on LaTeX.

PIC

Figure 3.1: Page dimensions of a book class.