3

I want to make a presentation with certain tasks, but since there are certain problems with using enumitem with beamer, I decided to make it myself, so I have this example code:

\documentclass{beamer}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{ifthen}

\usetheme{CambridgeUS}

\newcounter{tasknumber}
\stepcounter{tasknumber}
\newcounter{taskletter}

\resetcounteronoverlays{tasknumber}
\resetcounteronoverlays{taskletter}

\newcommand{\task}[1][ ]
{
        \ifthenelse{\equal{#1}{+}}{
        \stepcounter{tasknumber}\setcounter{taskletter}{0}}{} %<- why this doesn't work?
        Task \thetasknumber.
}

\newcommand{\taskl}
{
    \stepcounter{taskletter}
    \alph{taskletter})
}

\begin{document}
    \begin{frame}
        \frametitle{\task}
        \taskl ...
        \taskl ...
        \taskl ...
    \end{frame}
    %\setcounter{taskletter}{0}
    \begin{frame}
        \frametitle{\task[+]}
        \taskl ...
        \taskl ...
        \taskl ...
    \end{frame}
\end{document}

Obviously, I want to get first frame for first task with a), b) and c), and second frame for second task with a) b) and c) as well, but I get d), e) and f) on second frame. I wouldn't like adding \setcounter{taskletter}{0} after every frame.

5
  • 1
    My guess is that a frame's title actually is typeset after a frame's body… then the stepping is done too late
    – cgnieder
    Nov 8 '15 at 18:21
  • @cmhughes even when I delete \resetcounteronoverlays, I get the same problem
    – Ivan
    Nov 8 '15 at 19:12
  • \usepackage{etoolbox} \AtBeginEnvironment{frame}{\setcounter{taskletter}{0}} in the preamble seems to reset the counter for each frame. You may also want to add a % to the end of the line containing \ifthenelse to avoid excess whitespace on Tasks 2-n. Nov 9 '15 at 1:36
  • @MikeRenfro well, what if i have task 1 on frame 1, and task 1 on frame 2 again, but a), b) and c) on frame one, and d), e) and f) on frame 2...
    – Ivan
    Nov 9 '15 at 14:23
  • You may be able to make two types of custom frames, and reset taskletter on one of them, but I don't have a working example for that yet. Nov 9 '15 at 22:46
3

You should put \frametitle inside \task instead of the reverse.

\documentclass{beamer}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{ifthen}

\usetheme{CambridgeUS}

\newcounter{tasknumber}
\stepcounter{tasknumber}
\newcounter{taskletter}

\resetcounteronoverlays{tasknumber}
\resetcounteronoverlays{taskletter}

\newcommand{\task}[1][ ]
{
        \ifthenelse{\equal{#1}{+}}{
        \stepcounter{tasknumber}\setcounter{taskletter}{0}}{} %<- why this doesn't work?
        \frametitle{Task \thetasknumber.}
}

\newcommand{\taskl}
{
    \stepcounter{taskletter}
    \alph{taskletter})
}

\begin{document}
    \begin{frame}
        \task
        \taskl ...
        \taskl ...
        \taskl ...
    \end{frame}
    %\setcounter{taskletter}{0}
    \begin{frame}
        \task[+]
        \taskl ...
        \taskl ...
        \taskl ...
    \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.