Learn how to insert a GIF inside a beamer presentation through step by step tutorial

– Steps description

To insert a GIF into a beamer presentation we just need to follow these steps: 1) Convert the GIF into a sequence if PNG images, 2) make Beamer display these images at the correct speed, so as to make it look like the original GIF.

Consider the following “Thanks.gif” example:

Insert gif in beamer

Step 1: Convert GIF to PNGs

For the first step, we need an external program such as ImageMagick to get a sequence of images from a GIF file. The latter is achieved by the command convert or magick convert (depending on the version) .

– Let’s put the GIF image in a separate folder (GIF beamer in this example) as shown below:

– Then, if the GIF we want to insert is called Thanks.gif, we shall run the following command line in cmd:

magick convert -coalesce Thanks.gif Thanks.png

– (or, if this doesn’t work, use only magick). This will create a set of numbered
files Thanks-x, where x is the number of frames of our GIF (sequence of 6 PNG images in this example):

And now, we are ready for the next step!

Step 2: Embedded animation in Beamer

Now let’s see how we can embed this content inside beamer. The following code shows a minimal working example of how to put GIFs inside beamer presentations using the animate package:

% Embedded animations in Beamer
\documentclass{beamer}

% Theme choice
\usetheme{EastLansing}

% Required package
\usepackage{animate}

\begin{document}

\begin{frame}{GIFs in Beamer}
\centering
\animategraphics[loop,width=4cm]{10}{Thanks-}{0}{6}
\end{frame}

\end{document}

Compiling this code yields:

Let’s comment how the structure of the \animategraphics command works. First of all, the mandatory arguments are, following this order: the frame rate desired for the GIF (10ms in this example), the name of the images without the number that changes every time(Thanks- in this example) and the range of numbers of the images (in this case from 0 to 6).

Also, the optional command loop makes the GIF, once started, reproduce in a loop (like a real GIF, actually), and the optional command controls makes appear a control bar to basically start and stop the animation; which is omitted in this example.

Summary

  • A GIF in beamer can be inserted by splitting it to images and then animate them using the command \animategraphics.
  • \animategraphics command requires loading animate package. It accepts options like displaying images in a loop, set control buttons and set the delay between images.

Next Lesson: 12 Beamer Code Listing — Syntax highlighter