Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document

Formatting Information — An introduction to typesetting with LATEX

Chapter 2: Basic structures

Section 2.1: The Document Class Declaration

How to tell LATEX what type of document you want

In order to set things up correctly, LATEX needs to know up front what type of document you are going to be writing. There are probably lots of different types of document you deal with: in LATEX they are called classes of documents — ‘class’ is just a computing science word for ‘type’.

2.1.1 Document classes

To tell LATEX what class of document you are going to create, the first line of your file MUST identify it. To start a report, for example, you would type a \documentclass command like this as the first line of your document:

\documentclass{report}

There are four built-in classes provided, and many others that you can download (some may already be installed for you):

report

for business, technical, legal, academic, or scientific reports; and for theses and dissertations;

article

for white papers, magazine or journal articles, reviews, conference papers, essays, or research notes;

book

for books, booklets, or whole journals;

letter

for letters.

These default classes are fairly basic in terms of layout and design, in order to make them easier to customise by adding packages, which are the style and layout plug-ins that LATEX uses to let you automate formatting and change the design of your documents. Packages and classes are explained in more detail in Chapter 3 ‘Plugins and support’ below.

The article class in particular can be used for almost any short piece of typesetting by simply omitting the titling, changing the layout, and adding the relevant packages — like we saw in the Quick Start document in § 1.4 above.

The letter class is not much used: it provides a very old-fashioned layout. There are other more up-to-date classes for letters available for download.

2.1.2 Extending the default classes

The built-in classes are intended as starting-points, especially for drafts, and for compatibility when exchanging documents with other LATEX users. They come built into every installation of LATEX and if left unmodified, are guaranteed to format identically everywhere. They are not intended as final-format publication-quality layouts, and should not be used as such. For most other purposes, especially for publication, you use LATEX packages to extend these classes to do what you need. Some common ways to do this are:

  • The memoir package and the komascript bundle contain more sophisticated replacements for all the built-in classes, as well as additional ones;

  • Many academic and scientific publishers provide their own special class files for articles and books (some come with LATEX, others are on the publishers’ web sites for download);

  • Conference organisers may also provide class files for authors to write papers for submission, presentation, preprints, and proceedings;

  • Many universities provide their own thesis document classes in order to ensure exact fulfilment of their formatting requirements (many of these are on CTAN);

  • Businesses and other organisations can provide their users with private corporate classes on a central server and configure LATEX installations to look there first for packages, fonts, etc (not usually available to the public, of course);

  • There are nearly 300 document classes on CTAN (see http://www.ctan.org/topic/class)

The four default built-in document classes are therefore adequate for drafts or for sending to a colleague to edit, but they are not really usable for final-format publishing. For this you need to use packages to design it yourself, or (better) use a class file designed by your publisher or institution (or yourself!) to fit the type of publication. Quite often these are based on the default classes for compatibility, but typeset quite different output.

2.1.3 Document class options

The default class layouts were originally designed to fit as drafts on US ‘Letter’ size paper. However, the default paper size in TEX Live is now A4, so to create documents in North America, you need to specify the paper size in an optional argument in square brackets before the document class name, eg

\documentclass[letterpaper]{report}

The geometry package, which we will see later, lets you specify other bigger and smaller paper sizes.

Books and journals are not usually printed on office-size paper. Although for draft purposes LATEX’s layouts fit on the standard A4 or Letter stationery in your printer, it makes them look odd: the margins are too wide and the font size is too small, because the finished print job will normally be trimmed to a completely different size entirely — try printing a few pages of the PDF version of this chapter and then trimming the margins at the pale blue crop marks to make it 188 mm × 235 mm (the same as the Companion series) and you’ll see how it changes the appearance.

The other default settings in the built-in classes are for:

  1. 10pt type (all document classes)

  2. two-sided printing (books and reports) or one-sided (articles and letters)

  3. separate title page (books and reports only)

These can be modified with the following document class options which you can add in the same set of square brackets, separated by commas (the 10pt option is the default):

11pt

to specify 11pt type (headings, footnotes, etc get scaled up or down in proportion);

12pt

to specify 12pt type (again, headings etc get scaled to match);

oneside

to format one-sided printing for books and reports;

twoside

to format articles or letters for two-sided printing;

titlepage

to force articles to have a separate title page (books and reports get that automatically);

draft

makes LATEX highlight any hyphenation or justification problems with a small square in the right-hand margin so they can be located quickly by you or a proofreader. This option also sets graphics to print as an empty rectangle containing just the filename of the image, so that image-heavy drafts will print more quickly and use less ink or toner.

So, if you were using LATEX for a report to be in 12pt type on Letter paper, but printed one-sided in draft mode, you would use:

\documentclass[12pt,letterpaper,oneside,draft]{report}

The 10pt, 11pt, and 12pt settings cover between them probably 99.9% of all common text-document typesetting. There are extra options for other body type sizes in the extsizes bundle of document classes (extarticle, extbook, extreport, etc), and various national and international organisations supporting the visually-impaired have special large-type document class options.

Exercise 2.1 — Create a new document

  1. Use your editor to create a new, empty document

    If your editor insists on filling your new document with template material, delete it all so that the file is empty

  2. Type in a Document Class Declaration as shown above

  3. Add a font size option if you wish

  4. In North America, omit the a4paper option or change it to letterpaper

  5. Save the file (make up a name) ensuring the name ends with .tex

Global options

In addition to any options specific to the document class, it is also possible to put package options in the \documentclass options argument instead of in the \usepackage command (see § 3.1.2 below), provided they are not implemented by more than one package. Packages which do not implement the named option at all are supposed to silently ignore it.

  1. Readers familiar with SGML, HTML, and XML will recognise the concept as similar to the Document Type Declaration (it’s still called a ‘type’ there, not a ‘class’). 

  2. Theses and dissertations require an Abstract, which is provided in the report class but not in the book class. Many universities provide a special thesis class of their own. 

  3. The built-in letter class is rather idiosyncratic: there are much better ones you can use which you will find in the memoir package and the komascript bundle. 

  4. ‘Letter’ size is 8½″×11″, which is the trimmed size of the long-obsolete Demy Quarto, still in use in North America. Other common US office sizes are ‘Legal’, which is 8½″×14″, a ‘bastard’ (variant) cutting similar to the old Foolscap (8¼″×13¼″); Ledger or Tabloid (11″×17″, which is exactly twice ‘Letter’, in the same way that A3 is twice A4); and ‘Executive’ (7″×10″). The US still has many other sizes obsolete elsewhere, especially in government offices. International Organization for Standardization (ISO) standard ‘A’, ‘B’, and ‘C’ paper sizes, used everywhere else in the world, are still largely unknown in many parts of North America. 

  5. Note that the standard built-in document classes (book, article, report, or letter) only use the paper size to adjust the margins: they do not embed the paper size name in the PostScript or PDF output. For this you need the geometry package in order to ensure that the paper size name gets embedded correctly in the output, otherwise printers may select the wrong paper tray, or reject the job.