Filed under LaTeX

Add Spaces Between Citations in LaTeX

I had an issue where LaTeX wasn't adding spaces between references when I had multiple references in the same place.

So this:

of their own \cite{moretti:2012,saxenian:1996,casper:2007}.

was compiling as this:

of their own [Moretti, 2012,Saxenian, 1996,Casper, 2007].

To fix the problem, I simply added the space option for the cite package.


And now it looks as it should:

of their own [Moretti, 2012, Saxenian, 1996, Casper, 2007].

If you have spaces and don't want them, you can instead use the nospace option to remove the space between each citation.


Tagged ,

Subfigures in LaTeX

How can you create subfigures or subfloats in LaTeX? It's often easy to combine multiple figures from within a statistical package or image software, but it's generally best not to if you want to include subcaptions as text, for improved searchability.

Fortunately the subcaption package in LaTeX allows us to do this easily. (The subfigure and subfig packages have been deprecated, so it's best to use subcaption instead.)

How can you make more than one image or table be part of a LaTeX figure while still being able to create text captions for each?

Using the word clouds from my R word cloud tutorial, let's look at an example:

Wordcloud of national conventions

In order to make the figure containing the subfigures, we'll need to decide a few things first. Then it's just a matter of letting LaTeX know our preferences:

We also need to let LaTeX know to use the caption and subcaption packages. The full code for the example image above is included below, and also in a gist.




    \begin{subfigure}{0.4\textwidth} % width of left subfigure
        \caption{RNC} % subcaption
    \vspace{1em} % here you can insert horizontal or vertical space
    \begin{subfigure}{0.4\textwidth} % width of right subfigure
        \caption{DNC} % subcaption
    \caption{Wordcloud of national conventions} % caption for whole figure


For more information, this wikibooks article is useful.

Tagged , , ,

White Space in LaTeX

Extra spaces and line breaks in your source file are ignored. But there are several ways to force LaTeX to introduce white space to your documents.

The most simple commands to insert a specific amount of white space into your document are \hspace and \vspace.

To produce vertical space, use \vspace followed by the length of the space in brackets. This length can be represented in any units recognized by LaTeX, e.g. \vspace{2 in}. The space between the number and the unit is optional, so \vspace{2in} will also work.

Similarly, you can use \hspace to insert horizontal space in your document, e.g., \hspace{2 in}.

If \hspace and \vspace are not working as you would like (often at the beginning or end of a line or page), you can instead use \hspace and \vspace, which will force space to appear.

If you want to put in as much blank space as possible (while still maintaining page margins, etc.), you can use \hfill and \vfill.

Multiples of \vfill or \hfill on a particular page or in an environment will fill an even amount of the space. (E.g., if there are 6 inches to be filled and 3 \vfill's, each will take 2 inches.)


As well as \hspace{} and \hfill, there are some horizontal-specific commands for adding white space.

\quad creates a space whose size is relative to the current font size and font face. \quad is equal to \hspace{1em}. There are other commands that make spaces of sizes relative to \quad:

Horizontal space commands in LaTeX


Probably the most common white space command is \\. It is used to start a new paragraph.

That's not the only way to tell LaTeX to break a line. Here are a number of ways to do that in different situations:

command action
\ Start a new paragraph
\linebreak[number] Start a new line, option to request, not require
\newline Line break (only in paragraph mode)

\newline or \linebreak can be beneficial because they work inside the tabular environment (when a p column definition is used), where \ will not work within a cell.

As well as using \vspace{} and \vfill, there are some specific commands for vertical white space:

  • \smallskip
  • \medskip
  • \bigskip

The sizes of \smallskip, \medskip, and \bigskip are determined by the documentclass.

Example of skip sizes

There are also several kinds of ways to break a page, which sometimes creates white space:

command action
\pagebreak Starts a new page, using white space throughout to fill the full page before the break
\newpage Starts a new page, leaving the rest of the page before the break blank
\clearpage Like \newpage, but also prints all prior figures
\cleardoublepage Like \clearpage, but next page with print will be odd

Here's an example of the difference between \pagebreak and \newpage.

More information


Units in LaTeX

Discrete units

These are your basic units, like inches, centimeters, and points. Conversion of units from here and here.

These tables show the relative sizes of each unit:

Relative sizes of units in LaTeX, inches

Relative sizes of units in LaTeX, cm

Units defined relative to font sizes

There also are sizes that are relative to the current font face and font size. The size ex is usually the same as the height of an "x", and the size em is usually (but less often) equal to the width of an "M".

Since these are relative to your font, don't be surprised if your attempts look different than mine. Just like their absolute sizes, the size of ex relative to em is not consistent across fonts.

Examples of font-relative units

Units defined relative to document There also are units that have definitions relative to your document. These are determined based on your documentclass, and can also be explicitly changed.

A list of these and how to change them is available here. Some of the sizes are illustrated here.

command size
\paperwidth Width of page
\paperheight Height of page
\textwidth Width of text
\textheight Height of text
\linewidth Width of a line, usually equal to \textwidth, but varies with environment
\columnwidth Width of a column, usually same as \linewidth
\columnsep Distance between columns
\tabcolsep Separation between columns in a tabular environment
\parindent Paragraph indentation
\parskip The extra vertical space between paragraphs
\baselineskip Vertical distance between lines in a paragraph
\baselinestretch Multiplies \baselineskip
\unitlength Units of length in a picture environment
\topmargin Size of top margin
\evensidemargin Margin of even pages
\oddsidemargin Margin of odd pages

Next, we'll learn how to use these units to add white space.