1. 程式人生 > >LaTeX 中插入GIF圖片

LaTeX 中插入GIF圖片

參見博文:liam.page 和 voidcn

前提條件

  1. 安裝 ImageMagick 軟體 (因為要把 gif 圖片轉換成 png 序列),使用它的命令列工具 convert.exe
  2. 命令列下把 gif 轉換成 png 序列,實際,例如 convert latex_demo.gif -coalesce output-pngs/latex_demo.png
  3. latex 原始檔中引入巨集包 animate
  4. 編寫程式碼插入圖片

需要注意的是,不是所有的PDF閱讀器都能支援動畫。

示例

第一步安裝軟體就不演示了,第二步轉換圖片序列,第三步、第四步的示例原始碼如下:

% !TEX TS-program = xelatex
% !TEX encoding = UTF-8

% This is a simple template for a XeLaTeX document using the "article" class,
% with the fontspec package to easily select fonts.

\documentclass[11pt]{article} % use larger type; default would be 10pt

% 開啟下面的設定可以插入中文
\usepackage{ctex}
\usepackage{color}

\usepackage{fontspec} % Font selection for XeLaTeX; see fontspec.pdf for documentation
\defaultfontfeatures{Mapping=tex-text} % to support TeX conventions like ``---''
\usepackage{xunicode} % Unicode support for LaTeX character names (accents, European chars, etc)
\usepackage{xltxtra} % Extra customizations for XeLaTeX

%\setmainfont{Charis SIL} % set the main body font (\textrm), assumes Charis SIL is installed
%\setsansfont{Deja Vu Sans}
%\setmonofont{Deja Vu Mono}

% other LaTeX packages.....
\usepackage{geometry} % See geometry.pdf to learn the layout options. There are lots.
\geometry{a4paper} % or letterpaper (US) or a5paper or....
%\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent

% support the \includegraphics command and options
% PDF中插入GIF可以使用包 animate,前提是必須要先包含巨集包 graphicx
\usepackage{graphicx}
\usepackage{animate}

\title{PDF中插入GIF示例}
\author{LinTeX9527}
\date{\today}
%\date{} % Activate to display a given date or no date (if empty),
         % otherwise the current date is printed 

\begin{document}
\maketitle

\begin{center}
    \animategraphics[autoplay,
                    loop,
                    controls,
                    width=.7\textwidth]{15}{./latex-pngs/latex_demo-}{0}{80}    
\end{center}

\end{document}

原始GIF圖片如下

PDF 中動圖截圖

申明

歡迎轉載,請註明出處和作者,同時保留宣告。
作者:LinTeX9527
出處:https://www.cnblogs.com/LinTeX9527/p/11122268.html
本部落格的文章如無特殊說明,均為原創,轉載請註明出處。如未經作者同意必須保留此段宣告,且在文章頁面明顯位置給出原文連線,否則保留追究法律責任的權