9

I try to make multiple slides in beamer with 3 figures on each slide and the title. I would like to loop through the list/array of figures and set the frame title. The name of the figure files and the name of the frame should be different.

Here is the attempt:

\def\fnames{red, green, blue}

\foreach \name in \fnames {%

\begin{frame}{\name}
  \begin{columns}    
    \column{0.33\textwidth}
    \includegraphics[width=4.cm]{./plots/tot\name _log.eps} 
    \column{0.33\textwidth}
    \includegraphics[width=4.cm]{./plots/tot\name _log.eps} 
    \column{0.33\textwidth}
    \includegraphics[width=4.cm]{./plots/tot\name _log.eps} 
 \end{columns} 
\end{frame}%

}

The question: is it possible to set the title of the frame from a separate list or array. So instead of fnames, I would like to get it from: \def\tnames{white, gray, black}

Yuri
  • 93

1 Answers1

7

You can define a PGF array and access it via \pgfmathparse, the array index starts from 0 instead. I've used a,b,c for convenience.

EDIT: Added a general content loop but still it is not that economic on verbosity.

\documentclass{beamer}
\usepackage{tikz,etoolbox}
\usepackage{mwe} %<- for dummy images

\begin{document}

\def\fnames{a,b,c}
\def\tnames{{"white","gray","black"}}


\foreach \x[count=\xcount from 0] in \fnames {%
\def\myframecontents{}
\foreach\y in{1,2,3}{
    \gappto\myframecontents{%
        \column{0.33\textwidth}%
        \includegraphics[width=4.cm]{example-image-\x}%
    }
}

\pgfmathparse{\tnames[\xcount]}
\begin{frame}{\pgfmathresult}
   \begin{columns}    
       \myframecontents
   \end{columns} 
\end{frame}%
}
 \end{document}

enter image description here

percusse
  • 157,807
  • @Yuri: If you are happy with the answer, please upvote and accept it. That's the (nicest) way to say 'thanks' on TeX.SX. – Count Zero Jan 04 '13 at 19:40
  • Is it possible to make a loop inside the columns to repeat \column{0.33\textwidth} \includegraphics[width=4.cm]{example-image-\x} in a less verbose way? – kiss my armpit Mar 18 '13 at 19:32
  • I have been annoyed by the <use image_file_name.pdf> verbose too, while compiling beamer slides with an institute logo on each frame (where the logo was a pdf file). In latex/pdftex-def/pdftex.def, you can find the definition of \Ginclude@pdftex which appears to be used to insert pdf images, and hardcoded in it is the verbose. I deleted the five lines following \Gin@log that seemed to be the problem and I can now compile my slides with less unwanted verbose. However, I do not have the knowledge to do that in a better way (in particular: persistent across updates of pdftex). – Lay May 31 '13 at 21:58
  • 1
    @ClickMe Sorry I forgot this apparently. Now added a loop, but it's not that of a shortcut. – percusse Jun 01 '13 at 07:23
  • Thank you very much for this introduction to arrays in tikz. Unfortunately, the above code seizes to work for me if I add \usepackage[german]{babel} to the preamble (whereas, e.g., english does not cause any problems). Do you happen to know why? – anonymous Jul 22 '13 at 15:03
  • 1
    @anonymous Yes it is a known problem. Take a look at http://tex.stackexchange.com/questions/117732/tikz-and-babel-error – percusse Jul 22 '13 at 15:09