Tx · LaTeX & TikZ

How to Align Figures at the Top in Beamer

Published By the 9to5Science editorial team

At a glance

  1. 1. Use top alignment

    Set the Beamer columns environment to T alignment so each column begins at the same top position.

  2. 2. Size each image

    Set each graphic’s width relative to its own column, usually with width=\linewidth.

  3. 3. Check image edges

    If the visible pictures still look uneven, inspect and crop whitespace inside their image files.

To place two figures side by side at the same height in Beamer, use the columns environment with its uppercase T alignment option. Give each figure its own column and size the image relative to that column. This aligns the content at the top; if the pictures themselves still seem offset, check for blank margins inside the image files.

A complete example

The example below compiles as a Beamer presentation. It uses the sample images supplied by the mwe package, so you do not need to provide your own files. The graphicx package provides \includegraphics; Beamer loads it too, but it is included explicitly to make the dependency clear.

\documentclass{beamer}
\usepackage{graphicx}
\usepackage{mwe}

\begin{document}

\begin{frame}{Two top-aligned figures}
  \begin{columns}[T,onlytextwidth]
    \begin{column}{0.48\textwidth}
      \begin{figure}
        \centering
        \includegraphics[width=\linewidth]{example-image-a}
        \caption{First figure}
      \end{figure}
    \end{column}
    \begin{column}{0.48\textwidth}
      \begin{figure}
        \centering
        \includegraphics[width=\linewidth]{example-image-b}
        \caption{Second figure}
      \end{figure}
    \end{column}
  \end{columns}
\end{frame}

\end{document}

The T option requests top alignment for the columns. Use uppercase T, not lowercase t, when you want their contents aligned by their top edges rather than by the baseline of the first line. onlytextwidth makes the columns use the available text width. Each column is 0.48\textwidth, leaving a small gap between them.

Inside each column, \linewidth means the width currently available there. That makes width=\linewidth convenient: the image fits its column without needing to calculate a separate width. The figure environment groups the image and its caption; in Beamer it does not work like a floating figure in a typical article document.

If you are using minipages instead

For two images arranged with minipage rather than Beamer columns, use the [t] position option and begin each minipage with \vspace{0pt}:

\begin{minipage}[t]{0.48\textwidth}
  \vspace{0pt}
  \centering
  \includegraphics[width=\linewidth]{first-image}
  \captionof{figure}{First figure}
\end{minipage}\hfill
\begin{minipage}[t]{0.48\textwidth}
  \vspace{0pt}
  \centering
  \includegraphics[width=\linewidth]{second-image}
  \captionof{figure}{Second figure}
\end{minipage}

This variation requires \usepackage{caption} for \captionof. In a Beamer frame, the columns version is usually simpler. If you use minipages, the initial \vspace{0pt} helps ensure that the top alignment starts at the top of each minipage’s content.

When the visible image tops still differ

Top-aligning the LaTeX boxes does not necessarily align the visible subjects inside them. An image can contain blank space above the picture, or its subject can naturally start lower within the image bounds. LaTeX aligns the image boxes, including that whitespace.

You can crop margins with trim and clip:

\includegraphics[width=\linewidth,trim=0 0 0 12mm,clip]{first-image}

The four trim values are ordered as left, bottom, right, top. Adjust the last value to remove whitespace at the top. The clip option makes the crop take effect. Check the result carefully: trimming too much can cut off part of the figure. If the files have different proportions, they may also look different in size even when their widths match; choose a consistent height or crop the files if matching visual dimensions matters.

Common mistakes

  • Using [t] when you need top-edge alignment. In Beamer columns, use uppercase [T] for top alignment. Lowercase t aligns using the first line’s baseline, which can leave a small apparent offset.
  • Giving images a fixed width larger than their columns. Prefer width=\linewidth so each image fits the available column width.
  • Assuming the picture content fills its file. White borders or transparent margins are part of the image box. Crop them if the visible content, rather than the file boundary, needs to line up.
  • Adding manual vertical spacing before trying alignment options. First use the environment’s alignment setting. Manual \vspace adjustments can make one frame look right while causing inconsistent spacing elsewhere.

If the figures are not side by side, but instead need to sit at the top of a frame, place the content near the start of the frame and avoid vertical-centering commands or spacing that pushes it downward.

References

  1. The Beamer class: User Guide
  2. The Comprehensive LaTeX Symbol List and the LaTeX graphics bundle documentation

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