Tx · LaTeX & TikZ

How to Left-Align an Align Environment in Beamer

Published By the 9to5Science editorial team

At a glance

  1. 1. Enable fleqn

    Pass the fleqn option to beamer or amsmath so displayed mathematics starts at the text block’s left edge.

  2. 2. Remove the indent

    Set mathindent to zero if you want the equations flush with the frame’s normal left margin.

  3. 3. Use align normally

    Write aligned equations with alignment markers, usually placing & before the relation symbol.

Beamer normally centers displayed mathematics, including equations in an align environment. To place the entire display at the left side of the frame’s text area, enable the fleqn option and set the display-math indentation to zero.

The usual setup is:

\documentclass[fleqn]{beamer}
\setlength{\mathindent}{0pt}

\begin{document}

\begin{frame}{Left-aligned equations}
  \begin{align*}
    f(x) &= x^2 + 1 \\
    f'(x) &= 2x
  \end{align*}
\end{frame}

\end{document}

What fleqn does

fleqn means “flush-left equations.” It changes the placement of displayed mathematics from centered to left-aligned. In beamer, the equations are aligned with the frame’s normal text block, not necessarily with the physical edge of the paper.

The line

\setlength{\mathindent}{0pt}

removes the additional indentation that LaTeX may otherwise apply to a left-aligned display. If you prefer a small gap between the frame margin and the equations, use a positive length instead, for example:

\setlength{\mathindent}{1em}

Complete example with numbered equations

Use align rather than align* when you want equation numbers:

\documentclass[fleqn]{beamer}
\setlength{\mathindent}{0pt}

\begin{document}

\begin{frame}{A short derivation}
  \begin{align}
    (x+1)^2 &= x^2 + 2x + 1 \\
    x^2 + 2x + 1 &= 0
  \end{align}
\end{frame}

\end{document}

The ampersand specifies the alignment column. In the example, both equations are aligned at =. The \\ ends one row and starts the next.

If equation numbers are not needed, use align*:

\begin{align*}
  a &= b + c \\
  d &= e - f
\end{align*}

The starred environment is provided by amsmath, which beamer normally loads. If you are using a setup in which it is not available, load it explicitly with \usepackage{amsmath}.

Adjusting the indentation of one display

If the document already uses the fleqn setting but you want to adjust the indentation of one display, set \mathindent locally:

\begingroup
  \setlength{\mathindent}{0pt}
  \begin{align*}
    u &= v + w \\
    p &= q - r
  \end{align*}
\endgroup

This local adjustment controls the indentation only where the group is active. If the document does not use fleqn, setting \mathindent alone does not turn a centered display into a left-aligned one; fleqn must be enabled for that behavior. For a reliable document-wide change, however, put fleqn in the class options:

\documentclass[fleqn]{beamer}

Passing fleqn to amsmath

If you prefer to pass the option directly to amsmath, pass it before beamer loads the package:

\PassOptionsToPackage{fleqn}{amsmath}
\documentclass{beamer}
\usepackage{amsmath}
\setlength{\mathindent}{0pt}

Do not normally use both \documentclass[fleqn]{beamer} and \PassOptionsToPackage{fleqn}{amsmath}. Choose one method. Passing the option through the document class is the simpler beamer configuration.

Left-aligning the equations versus the alignment points

These are two separate settings:

  1. fleqn controls where the entire displayed equation block begins.
  2. & controls the internal columns in align.

For example:

\begin{align*}
  x &= y + z \\
  \alpha + \beta &= \gamma
\end{align*}

The complete block is flush left because of fleqn, while both rows line up at their equals signs because each row contains &=.

If you omit the alignment markers, align is usually not the right environment. For one equation or a simple multiline expression, use equation, gather, or multline depending on the desired layout. align is intended for one or more alignment columns.

Common mistakes

Wrapping align in flushleft

This is not the preferred solution:

\begin{flushleft}
  \begin{align*}
    x &= y
  \end{align*}
\end{flushleft}

align is already a display-math environment and controls its own spacing. A surrounding paragraph-alignment environment can produce confusing spacing and does not replace the fleqn setting.

Expecting the equation to touch the paper edge

“Flush left” means flush with the current text block. Beamer still has frame margins, so the equation normally begins inside those margins. If you need to change the frame’s actual text margins, use beamer’s frame margin settings separately; do not use negative \mathindent as a general margin adjustment.

Using \\ after the final row

A final row normally does not need a line break. Write:

\begin{align*}
  x &= y + z \\
  p &= q
\end{align*}

rather than adding an unnecessary \\ after p &= q.

Forgetting that align* suppresses numbers

Use align for numbered equations and align* for unnumbered equations. You can suppress an individual number inside align with \notag or \nonumber.

References

  1. The amsmath Package documentation
  2. The beamer class documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.