這個循環算術有什麼問題?

這個循環算術有什麼問題?

我想在beamer.頁碼設定失敗page=\numexp \ii * 2 \relax。程式碼

\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}

輸出對我來說沒有意義;試圖解決它並\newcounter{ii}沒有幫助。

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

輸出與\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
作業系統:Debian 8.5

答案1

我從 轉換beamerarticle,只是為了可以使用demo模式graphicx。但正如我在評論中所說,有兩個問題:

  1. \numexpr,不是\numexp正確的語法,並且

  2. 你需要\the\numexpr為了讓它可以被尋找字串的東西消化。 (要看到這一點,請嘗試\numexpr 0\relax在文件中輸出與\the\numexpr 0\relax

正如OP所指出的,將subfigure寬度設定為0.45\textwidth每行允許兩個數字。

這是 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}

在此輸入影像描述

相關內容