4

I want to loop 4x2 figures on many pages in beamer. The page number setting fails page=\numexp \ii * 2 \relax. Code

\documentclass{beamer}
\usepackage{pgffor}    
\usepackage{graphicx}                                                          
\usepackage{subcaption} % http://tex.stackexchange.com/a/37597/13173

\begin{document}
\begin{frame}[allowframebreaks]
    \foreach \ii in {1,...,4}{
    \begin{figure}
    \centering% not \center!
    \begin{subfigure}{0.5\textwidth}
      \includegraphics[scale=0.2, page=\ii]{{Rplots.bland.altman.1}.pdf}
      \caption{Image \ii.}
    \end{subfigure}
    \begin{subfigure}{0.5\textwidth}
      \includegraphics[scale=0.2, page=\numexp \ii * 2 \relax]{{Rplots.bland.altman.1}.pdf}
      \caption{Image \ii.}
    \end{subfigure}
    \end{figure}
    }
\end{frame}
\end{document}

Output does not make sense to me; trying to solve it by \newcounter{ii} does not help.

! Undefined control sequence.
\GPT@page ->\numexp 
                    \ii * 2 \relax 
l.23 \end{frame}

Output with \the\numexp ...

...
? 
! You can't use `the character 1' after \the.
\ii ->1

l.23 \end{frame}

? 
! Missing \endcsname inserted.
<to be read again> 
                   \relax 
l.23 \end{frame}

? 
! Missing { inserted.
<to be read again> 
                   *
l.23 \end{frame}

? 
! Missing \endcsname inserted.
<to be read again> 
                   \relax 
l.23 \end{frame}

TeXLive: 2016
OS: Debian 8.5

Werner
  • 603,163
  • 2
    \includegraphics[scale=0.2, page=\the\numexpr \ii * 2 \relax]{{Rplots.bland.altman.1}.pdf} 2 mistakes: 1) \numexpr, not \numexp and 2) you need \the\numexpr in order to make it digestible by something looking for a string. – Steven B. Segletes Nov 15 '16 at 19:57
  • @StevenB.Segletes It seems to work! Can the images made smaller during the process? - - They are very big for LaTeX. – Léo Léopold Hertz 준영 Nov 15 '16 at 20:03
  • 2
    It's called \numexpr, not \numexp, and it has to resolve to a number, so use page=\number\numexpr\ii*2 or page=\the\numexpr\ii*2. – Werner Nov 15 '16 at 20:04
  • You control the size of the images by way of the scale= parameter. Perhaps using \width= or height= would work better for you, instead of scale=. – Steven B. Segletes Nov 15 '16 at 20:05
  • @StevenB.Segletes Can the physical size too be controlled? My images are just too big in MBs. – Léo Léopold Hertz 준영 Nov 15 '16 at 20:05
  • 2
    To reduce the file size, you literally have to save the images in a smaller (reduced resolution) format before including them in a LaTeX document. – Steven B. Segletes Nov 15 '16 at 20:10

1 Answers1

6

I converted from beamer to article, just so that I could use demo mode of graphicx. But there were two issues, as I said in my comment:

  1. \numexpr, not \numexp is the proper syntax, and

  2. you need \the\numexpr in order to make it digestible by something looking for a string. (to see this, try outputting \numexpr 0\relax in a document versus \the\numexpr 0\relax)

As the OP noted, setting the subfigure width to 0.45\textwidth allows two figures per row.

Here is the MWE.

\documentclass{article}%{beamer}
\usepackage[demo]{graphicx}
\usepackage{pgffor,subcaption}                                                            

\begin{document}
%\begin{frame}[allowframebreaks]
    \foreach \ii in {1,...,4}{
    \begin{figure}
    \centering% not \center!
    \begin{subfigure}{0.45\textwidth}
      \includegraphics[scale=0.2, page=\ii]{{Rplots.bland.altman.1}.pdf}
      \caption{Image \ii.}
    \end{subfigure}
    \begin{subfigure}{0.45\textwidth}
      \includegraphics[scale=0.2, page=\the\numexpr \ii * 2 \relax]{{Rplots.bland.altman.1}.pdf}
      \caption{Image \ii.}
    \end{subfigure}
    \end{figure}
    }
%\end{frame}
\end{document}

enter image description here