logo

How to Insert GIF Animations into a PDF File Using LaTeX 📂Writing

How to Insert GIF Animations into a PDF File Using LaTeX

Description

Using \animategraphics from the animate package allows you to compile a pdf file with GIF-like animations inserted. Such animations can be viewed on JavaScript-supporting pdf viewers like Adobe Acrobat or KDE Ocular.

\animategraphics[options]{frame}{file name}{start}{end}

  • options: Defines settings like size or autoplay. See the homepage for more details.
    • autoplay: Autoplay
    • loop: Loop playback
  • frame: Frame rate (number of images played per second)
  • file name: Enter the file name. The file name must be written according to the following rules, excluding the part where numbers go.
    • Image file name rule:
      • The file name should end with a non-negative integer.
      • These numbers must be consecutive.
  • start: The number of the image where the animation starts
  • end: The number of the image where the animation ends

For instance, if you want to create an animation that autoplays and loops with a frame rate of 2 images per second using 4 image files anim_1.png, anim_2.png, anim_3.png, anim_4.png, you would write as follows.

\animategraphics[autoplay, loop]{2}{anim_}{1}{4}

Example

\animategraphics[width=\textwidth, autoplay, loop]{20}{./Jiwon/Jiwon_}{1}{122}

3508_anim_1.webp

Of course, it’s also possible to insert multiple animations into one figure using subplots.

\begin{figure}
    \subfloat[Park Ji-Won]{\animategraphics[width=0.5\textwidth, autoplay, loop]{20}{./Jiwon/Jiwon_}{1}{122}}
    \subfloat[Baek Ji-Heon]{\animategraphics[width=0.5\textwidth, autoplay, loop]{20}{./Jiheon/Jiheon_}{1}{111}}
    \caption{fromis\_{9}}
\end{figure}

3508_anim_2.webp

Full code

\documentclass{article}
\usepackage{graphicx} % 이미지 삽입에 필요함.
\graphicspath{{./images/}} % 이미지 경로.

\usepackage{animate} % gif 애니메이션 생성.
\usepackage{subfig} % \subfolat

\begin{document}

\section{How to insert GIF animation}

\animategraphics[width=\textwidth, autoplay, loop]{20}{./Jiwon/Jiwon_}{1}{122}

\begin{figure}
    \subfloat[Park Ji-Won]{\animategraphics[width=0.5\textwidth, autoplay, loop]{20}{./Jiwon/Jiwon_}{1}{122}}
    \subfloat[Baek Ji-Heon]{\animategraphics[width=0.5\textwidth, autoplay, loop]{20}{./Jiheon/Jiheon_}{1}{111}}
    \caption{fromis\_{9}}
\end{figure}

\end{document}