2

I'm using LaTeX beamer and the forloop-package to create a for loop, and I want to use the counter inside an \only-command. Here is a MWE (or more like non-working example):

\documentclass[12pt]{beamer}

\usepackage{forloop}

\begin{document}
  \begin{frame}
  \begin{center}
    \newcounter{slideno}
    \forloop{slideno}{1}{\value{slideno} < 20}{
      \only<\value{slideno}>{\arabic{slideno}}%
    }
  \end{center}
\end{frame}
\end{document}

The error message is:

! LaTeX Error: Command \c@slideno already defined.
               Or name \end... illegal, see p.192 of the manual.

Now, the post over here[0] tells me that using counters like this in \only should be possible, and in fact, if I comment out the for-loop (and add a \setcounter), it works like a charm.

Does the for-loop some magic to the counter? Can I somehow circumvent this?

Thanks a lot,

Lukas

[0] usage of \only with counter, pdfcomment and beamer class

1

Since frame itself does replicate the content somehow with each slide, a \newcounter command inside a frame with more than slide is of course leading to a multiple definition of slideno, which is wrong.

Put the \newcounter{slideno} definition into the preamble (which is always a good idea for counters.)

There's also missing % in the \forloop

   \forloop{slideno}{1}{\value{slideno} < 20}{
      \only<\value{slideno}>{\arabic{slideno}}%
    }

will lead to numbers moving to the right, whereas

   \forloop{slideno}{1}{\value{slideno} < 20}{%
      \only<\value{slideno}>{\arabic{slideno}}%
    }

will provide 'stationary' numbers.

\documentclass[12pt]{beamer}

\usepackage{forloop}

\newcounter{slideno}

\begin{document}
  \begin{frame}
  \begin{center}
    \forloop{slideno}{1}{\value{slideno} < 20}{%
      \only<\value{slideno}>{\arabic{slideno}}%
    }
  \end{center}
\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.