10

I want to include a sequence of images in Beamer (although it can be in another type of document). Something similar to the option Photo Album in LibreOffice and MS PowerPoint.

What I did is to make a template (that I can modify):

%s
\begin{frame}
    \frametitle{%s}
    \framesubtitle{%s}
    \centering
    \includegraphics[width=0.9\textwidth]{%s} 
\end{frame}

And then I use a Python script to generate the code for each frame, like this:

tex_file = open(filename + '.tex', 'a+')
for name in list_files:
    print >> tex_file, s1 %(comment, title, subtitle, name)

tex_file.close()

After that I just use an \include in my main file to add the sequence of images.

My question: Is there a package for this task? or a better way to do it?

  • Yes you can do this with loops in (La)TeX... no problem. What does the sequence look like... photo_001.jpg, photo_002.jpg, ...? – Werner Sep 23 '14 at 3:43
  • Yes, I generate the images automatically and name them like that: im-vf=1.png, im-vf=2.png, ... – nicoguaro Sep 23 '14 at 3:55
14

Here is an option using multido:

enter image description here

\documentclass{beamer}
\usepackage{multido}
\begin{document}
\multido{\i=1+1}{9}{%
  \begin{frame}
    \frametitle{Title: \i}
    \framesubtitle{Subtitle: \i}
    \centering
    \includegraphics[width=.9\linewidth]{example-image-\i}
  \end{frame}
}
\end{document}

The syntax is \multido{<var>=<start>+<inc>}{<times}{<stuff>} which defines <var> to be <start>, incremented by <inc> a total of <times>-1 times (since the first value counts as an iteration), and with each iteration it executes <stuff>. The special \i-notation means that <var> will be an integer.

The above example assumes minimal changes from one element to the next. If, for example, you have varied content for the frame title, subtitle and any additional comments on a per-photo basis, then using a list-like approach would be far better. For than, any of the techniques mentioned in How to iterate over a comma separated list? would be helpful.

  • Thanks, this is really useful! Although the \r and \n variables are not perfect they work. For more elaborated things I will look at iteration over a CSV file. – nicoguaro Sep 23 '14 at 21:53
9

I have a tex file that I wrote to produce a display of photos that does something like this. For me the goal is to arrange a changing collection of photos on a grid covering the page. I use tikz to both loop over the photos, that are stored as a comma separated list of image filenames, and to place the photos.

As you are talking about generating the list of filenames via python you could easily populate a variable list like the one used below.

Here is a cut down version:

\documentclass{article}
\usepackage{mwe}
\usepackage{graphicx}
\usepackage{tikz}

\def\MyImages{example-image-a,example-image-b,example-image-c}% list of images
\begin{document}
  \newdimen\X
  \begin{tikzpicture}[overlay,
          picture/.style={draw,rectangle,anchor=#1,inner sep=0pt,outer sep=0pt}
     ]
     \X=0mm
     \foreach \Image in \MyImages {
       \node[picture=north west] at (\X,-101.5mm)
             {\includegraphics[width=49.5mm,height=35mm]{\Image}};
       \global\advance\X by 49.5mm
     }
  \end{tikzpicture}
\end{document}

This produces:

enter image description here

1

enter image description here

This is possible using the \multiinclude command from beamer's xmpmulti package.

Assuming the images are called fig-0.png, fig-1.png etc. the macro can be used like this:

\documentclass{beamer} 
\usepackage{xmpmulti} 

\begin{document}
\begin{frame}
\multiinclude[<+->][format=png, graphics={width=\textwidth}]{fig}
\end{frame} 
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.