Thursday, November 8, 2012

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.)

Horizontal

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

Vertical

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:

commandaction

\\Start a new paragraph
\linebreak[number]Start a new line, option to request, not require
\newlineLine break (only in paragraph mode)
Line breaks in LaTeX

\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:

commandaction

\pagebreakStarts a new page, using white space throughout to fill the full page before the break
\newpageStarts a new page, leaving the rest of the page before the break blank
\clearpageLike \newpage, but also prints all prior figures
\cleardoublepageLike \clearpage, but next page with print will be odd
Page breaks in LaTeX

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

More information


--
This post is one part of my series on LaTeX.

No comments:

Post a Comment