LaTeX Typesetting – Basics

[This article was first published on Software for Exploratory Data Analysis and Statistical Modelling, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The LaTeX typesetting is used to create professional looking documents on a home computer. It may have a steeper learning curve than using a Word Processor, but this initial effort will often pay off reasonably quickly. The system is almost a necessity for anyone writing documents with a large amount of mathematics as most alternatives are painful to use efficiently.

Fast Tube
Fast Tube by Casper

In a LaTeX document we need to specify a class, which is a file that defines the formatting styles applied to a document. The standard classes available include article, book, letter and custom classes can be defined to create different visual styles for a LaTeX document.

At the top of the document we use the documentclass command to specify the class to use for the document. For an article we would have:


The preamble after this command and before the main body of the document can be used to include other packages, define environments or various other actions. The body of the document is included within these commands:


It is straightforward to include title information in the document by specifying an author, title and date then followed by a maketitle command. Note that note all of these are compulsory for a document. A simple example of creating a title:

title{Using R}
author{An R Fanatic}

We write the text of our LaTeX document as we would a basic text document and then add commands where we want to make changes to the appearance of text. For example we might want to emphasise some of the text using the emph:

The emph{assumptions} underlying the choice of model need to be investigated.

There are a few special symbols worth being aware of when creating LaTeX documents:

  • Percentages need to be specified as %, otherwise they will be confused as meaning a comment so will be ignored.
  • Curly brackets are special characters so you need to write { and } if you want to use them in the text.
  • Hash (#), dollar ($) and ampersand (&) are all also special characters.

To align a block of text the center, flushright and flushleft environments can be used. Examples of using these:

Text is centred.
Text is flush right.
Text is flush left.

The size of the font can be changed using various declarations, which include small, normalsize, large, Large and LARGE.

Useful software for working with LaTeX includes:

Other useful resources are provided on the Supplementary Material page. A google search will also through up a large number of good online resources for LaTeX.

To leave a comment for the author, please follow the link and comment on their blog: Software for Exploratory Data Analysis and Statistical Modelling. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)