我在 LaTeX 中使用 Beamer 类创建了一个代码,以 20x20 格式生成 Beamer 演示文稿,但在堆栈溢出有人告诉我可怕!为什么?代码是:
\documentclass[12pt,xcolor=x11names]{beamer}
\usecolortheme[named=darkgray]{structure}
\usetheme{Warsaw}
\usepackage{fourier}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[spanish]{babel}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage{tikz}
\setbeamertemplate{navigation symbols}{}
\hypersetup{%
pdfpagemode=FullScreen,%
pdfstartpage=1,%
colorlinks=false,%
linkcolor=magenta,%
pdftitle={Lorem Ipsum},%
pdfauthor={Dolor, Et},%
pdfsubject={Lorem},%
pdfkeywords={lorem, ipsum, dolor}%
}
\title{Dolor Ipsum}
\subtitle{Lorem Ipsum et}
\author{Dolor Et}
\date{}
\begin{document}
{
\setbeamercolor{background canvas}{bg=darkgray}
\begin{frame}[plain]
\transduration{5}
%\titlepage
\centerline{\textcolor{white}{\textbf{\large{Dolor Ipsum}}}}
\vspace{.3cm}
\centerline{\textcolor{white}{\textbf{\large{Lorem Ipsum}}}}
\vspace{1cm}
\centerline{\textcolor{black}{\textbf{Dolor Et}}}
%\centerline{\small\color[rgb]{0.01,0.33,0.58}
%\textbf{http://www.lorem.org}}
\end{frame}
}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image1.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image2.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image3.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image4.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image5.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image6.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image7.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image8.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image9.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image10.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image11.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image12.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image13.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image14.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image15.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image16.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image17.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image18.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image19.jpg}
};
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{image20.jpg}
};
\end{tikzpicture}
\end{frame}
\end{document}
答案1
在以下两种情况下,我假设您的图像实际上名为 imageN.jpg,其中 N 是 1、2、3、...、20:
选项 1(删除 180 行代码,添加回 30 行,并允许您在一个地方更改所有框架的样式):
添加到序言
\newcommand{\myframe}[1]{
\begin{frame}[plain]
\transduration{20}
\begin{tikzpicture}[remember picture,overlay]
\node[at=(current page.center)] {
\includegraphics[height=\paperheight]{#1}
};
\end{tikzpicture}
\end{frame}
}
并用 20 个命令替换 20 个帧中的每一帧\myframe{imageN.jpg}
。
\myframe
选项 2,用循环替换 20 条命令(节省另外 17 行):
\foreach \n in {1,...,20} {
\myframe{image\n.jpg}
}
此外,在这个特定示例中,该pdfpages
包似乎未被使用。删除所有注释行和pdfpages
包,并将原始表示转换为循环版本,263 行代码现在只有 58 行。
以下是闪电风格投影仪演示课程和演示的开始:
beamer-lightning.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{beamer-lightning}[2011/10/09 v0.1 Modified beamer class for ``lightning'' presentations]
\newcommand{\slideduration}{15}
\DeclareOption{ignite}{%
\renewcommand{\slideduration}{15}%
}
\DeclareOption{pechakucha}{%
\renewcommand{\slideduration}{20}%
}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{beamer}}
\ProcessOptions
\LoadClass{beamer}
\setbeamertemplate{navigation symbols}{}
\RequirePackage{hyperref}
\hypersetup{pdfpagemode=FullScreen}
\newenvironment{slide}[1]
{\begin{frame}[environment=slide]
\transduration{\slideduration}
\frametitle{#1}}
{\end{frame}}
\endinput
pk-示例.tex
% class option ignite: 15 second slide duration
% class option pechakucha: 20 second slide duration
\documentclass[ignite]{beamer-lightning}
\usetheme{Boadilla}
\title{There Is No Largest Prime Number}
\subtitle{With an introduction to a new proof technique}
\institute[Alexandria]{Department of Mathematics \\
University of Alexandria}
\author[Euclid]{Euclid of Alexandria \\ \texttt{[email protected]}}
\date[ISPN '80]{27th International Symposium of Prime Numbers}
\usepackage{pgffor} % for \foreach command below
\begin{document}
% The slide environment creates a slide with an automatic transition time
\begin{slide}
\titlepage
\end{slide}
% For presentations where each slide is regular text and content:
\begin{slide}{What Are Prime Numbers?}
\begin{definition}
A \alert{prime number} is a number that has exactly two divisors.
\end{definition}
\begin{example}
\begin{itemize}
\item 2 is prime (two divisors: 1 and 2).
\item 3 is prime (two divisors: 1 and 3).
\item 4 is not prime (\alert{three} divisors: 1, 2, and 4).
\end{itemize}
\end{example}
\end{slide}
% For presentations where each slide is a giant image named
% imageN.png or similar:
\foreach \slidetitle in {
{Title 3, which has a comma}, Title 4, Title 5, Title 6, Title 7, Title 8,
Title 9, Title 10}
{
\begin{slide}{\slidetitle}
\begin{center}
Here lies image\thepage{}.png
\end{center}
\end{slide}
}
% For presentations where each slide is a giant image named
% arbitrarily:
\foreach \slidetitle / \imagefile in {
{Title 11 (with embedded /)} / imagexi.png,
Title 12 / image12.pdf,
Title 13 / number13.jpg,
Title 14 / file14.png,
Title 15 / 15.png,
Title 16 / sixteen.pdf,
Title 17 / xvii.png,
Title 18 / 18.pdf,
Title 19 / 19.png,
Title 20 / twenty.pdf}
{
\begin{slide}{\slidetitle}
\begin{center}
Here lies \imagefile
\end{center}
\end{slide}
}
\end{document}
答案2
我不会把你的代码称为“糟糕的”,但我确实注意到,除其他事项外:
- 包
fontenc
、inputenc
、babel
、hyperref
和pdfpages
根本不需要加载,并且\hypersetup{...}
可以省略冗长的命令; - 您设置了宏
\title
、\subtitle
、\author
和\date
,但它们并没有被使用; - 据我所知,您需要该
tikz
软件包来将图像置于相应页面的中心。只需在命令\centering
之后\transduration
和之前添加一条简单指令,即可更经济地完成此操作\includegraphics
; - 在第 1 帧上,您有多个
\centerline
和\textbf
命令。将它们全部删除,然后直接插入到\centering\bfseries
帧顶部; xcolor=x11names
语句中的选项是不必要的,\documentclass
因为您使用的唯一“颜色”是white
、black
和——它们是gray
darkgray
始终可用何时xcolor
加载;- 与此同时,我看到 Mike Renfro 就如何简化循环处理 1 到 20 张图像提供了一些意见。我对此没有什么可补充的,只能说我完全同意他们的观点。另外:如果您确实使用了 Mike Renfro 的代码,则需要加载包,
tikz
或者至少加载pgffor
包(由包加载tikz
)才能加载\foreach
宏。
答案3
首先他们并没有说可怕,但是严重肿胀这可能意味着它比预期的要长得多。其次,有人问如何每 20 秒更换一次幻灯片,而你提供了 20 多张幻灯片,重复了 20 次,代码完全相同。
我不知道这是否是你的本意,但我不得不同意 SE 上的评论,即你的答案对 OP 正在寻找的答案没有帮助。你本可以做的是使用动画包以每 20 秒一张的速度重播 20 多张图片。我不知道还能说什么。