LaTeX Typesetting – Basics

November 28, 2010

(This article was first published on Software for Exploratory Data Analysis and Statistical Modelling, and kindly contributed to R-bloggers)

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , ,

Comments are closed.


Mango solutions

RStudio homepage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training


CRC R books series

Contact us if you wish to help support R-bloggers, and place your banner here.

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)