2

I would like to arrange images in a beamer presentation without having to set them in a predefined position. Is there a package or a fast way to place randomly into the beamer a given number of images?

\begin{figure}
    \includegraphics[width=0.3\linewidth]{img1}
    \includegraphics[width=0.3\linewidth]{img2}
    \includegraphics[width=0.3\linewidth]{img3}
\end{figure}

I would like to move them in the beamer and not having them on the same line.

  • 1
    Welcome to TeX.SX! Please provide a minimal working example (MWE) to demonstrate your set-up. – Andrew Swann Mar 7 '15 at 14:47
  • How move, during presentation or while preparing the document? – AlexG Mar 7 '15 at 15:29
  • I updated my answer with a command allowing you to use any number of images. – Gonzalo Medina Mar 7 '15 at 17:27
4

You can use TikZ's nodes and rnd to randomize the position; the command \PlaceImageRnd has as mandatory argument a comma separated list of the image name files:

\PlaceImageRnd{<image-1>,<image-2>,...,<image-n>}

The line

\pgfmathsetseed{\pdfuniformdeviate 10000000}

makes each run of the code to update the locations.

The code:

\documentclass{beamer}
\usepackage{tikz}

\newcommand\PlaceImageRnd[1]{%
  \begin{tikzpicture}
  \pgfmathsetseed{\pdfuniformdeviate 10000000}
  \pgfmathparse{2.0*rnd+1.0}
  \foreach \Image in {#1}
  {
    \node at (10*rnd,6*rnd) 
      {\includegraphics[width=0.3\linewidth]{\Image}};
  }
  \end{tikzpicture}% 
}

\begin{document}

\begin{frame}
\PlaceImageRnd{example-image-a,example-image-b,example-image-c}
\end{frame} 

\end{document}

On the first run I got:

enter image description here

  • Is it possible to ensure the nodes don't overlap? – Croolman Jun 11 at 8:46

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.