
いくつかの画像を含む画像ディレクトリがあります:
p1.jpg
p2.jpg
p3.jpg
p4.jpg
背景画像をフレームに設定する次の環境もあります。
\newenvironment{imageframe}[1]
{% Set background image
\usebackgroundtemplate{%
\begin{tikzpicture}[remember picture,overlay]%
\node[inner sep=0] at (current page.center) {\includegraphics[width=\paperwidth,height=\paperheight]{#1}};%
\end{tikzpicture}%
}%
\begin{frame}%
}
{
\end{frame}%
}
次のように使用されます。
\begin{imageframe}{p1.jpg}
\frametitle{Nothing was the same.}
Always felt like my vision been bigger than the bigger picture.
\end{imageframe}
有効な背景画像 (p1.jpg、...、p4.jpg) のリストを保持する変数 (またはコマンド) を作成し、環境が呼び出されるときに画像パスを明示的に指定しないようにしたいと思います。代わりに、imageframe が最初に呼び出されたときに最初の画像 (p1.jpg) が選択され、2 回目に 2 番目の画像 (p2.jpg) が呼び出される、というようにする必要があります。オーバーフローは p1.jpg にループバックする必要があります。
答え1
カウンターがなく、事前に画像の枚数を指定する必要もありません。示されている方法で画像のリストを定義するだけで完了です。
\documentclass{beamer}
\usepackage{tikz}
\newenvironment{autoimageframe}
{% Set background image
\usebackgroundtemplate{%
\begin{tikzpicture}[remember picture,overlay]
\node[inner sep=0] at (current page.center) {%
\includegraphics[width=\paperwidth,height=\paperheight]{\currentbgimage}%
};
\end{tikzpicture}%
\expandafter\swapbgimage\bgimagelist
}%
\begin{frame}}
{\end{frame}}
\newcommand\currentbgimage{\expandafter\usebgimage\bgimagelist}
\newcommand{\usebgimage}{}
\def\usebgimage#1#2\bgimagelist{#1}
\newcommand{\swapbgimage}{}
\def\swapbgimage#1#2\bgimagelist{%
\gdef\bgimagelist{#2{#1}\bgimagelist}%
}
% Define here the list of images
% Each image is in a braced group
% REMEMBER to have \bgimagelist at the end
\newcommand\bgimagelist{
{example-image}
{example-image-a}
{example-image-b}
{example-image-c}
\bgimagelist
}
\begin{document}
% Thanks to Percusse for the code here
\foreach\x in{1,...,9}{
\begin{autoimageframe}
\frametitle{Nothing was the same.}
Always felt like my vision been bigger than the bigger picture.
\end{autoimageframe}
}
\end{document}
マクロ\currentbgimage
はリストの最初の項目を使用し、\swapbgimage
最初の項目を最後に配置します。
答え2
いくつかのマクロと名前リストを生成し、mod
操作を介してループすることができます。
\documentclass{beamer}
\usepackage{tikz,mwe}% For dummy images
\newcounter{backgroundimagecounter}
\setcounter{backgroundimagecounter}{0}
\newenvironment{autoimageframe}
{% Set background image
\usebackgroundtemplate{%
\begin{tikzpicture}[remember picture,overlay]%
\pgfmathsetmacro\currentbackgroundimage{\backgroundimagenamelist[int(Mod(\value{backgroundimagecounter},\numberofbackgroundimages))]}%
\node[inner sep=0] at (current page.center) {\includegraphics[width=\paperwidth,height=\paperheight]{\currentbackgroundimage}};%
\end{tikzpicture}%
\stepcounter{backgroundimagecounter}%
}%
\begin{frame}%
}
{
\end{frame}%
}
\def\backgroundimagenamelist{{
"example-image",
"example-image-a",
"example-image-b",
"example-image-c"}}
\def\numberofbackgroundimages{4}
\begin{document}
\foreach\x in{1,...,9}{
\begin{autoimageframe}
\frametitle{Nothing was the same.}
Always felt like my vision been bigger than the bigger picture.
\end{autoimageframe}
}
\end{document}