2

I am using something like the following. I want to get same counter for problems and solutions eg problem 1 with solution 1. However I am getting problem 1 with solution 2 which is confusing to me. Any help would be appreciated.

\documentclass[9pt]{beamer}
\usepackage{epsfig,amsthm,subfigure,amssymb,amsmath,amsfonts}
\setbeamertemplate{theorems}[numbered]
\newcommand{\thi}[1]{\begin{theorem}#1 \end{theorem}}
\newcommand{\defi}[1]{\begin{definition}#1 \end{definition}}
\newcommand{\prob}[1]{\begin{problem}#1 \end{problem}}
\newcommand{\solu}[1]{\begin{solution}#1 \end{solution}}
\title{course 2} % The short title appears at the bottom of every slide, the full title is only on the title page

\author{JOhn Doe} % Your name
\institute[] % Your institution as it will appear on the bottom of every slide, may be shorthand to save space
{
Department of xx \\ % Your institution for the title page
\smallskip
school name % Your email address
}
\date{}
\smallskip
\begin{document}
\maketitle
\begin{frame}
\thi{}
\prob{}
\solu{}
\end{frame}
\end{document}
1
  • Off-topic: you don't need to load amsthm, amssymb, amsmath and amsfonts, beamer will load them automatically Commented Sep 6, 2022 at 8:08

1 Answer 1

3

From what I can tell, those environments are hardcoded in the beamer theorem template to use the same counter as theorem. Why? Don't know.

For example, in beamerbasetheorems.sty we see the command \newtheorem{solution}[theorem]{\translate{Solution}}. The optional argument [theorem]. in the middle specifies that it should use the same counter as theorem. problem also uses that counter, so the same counter is increased when any of these are used.

However, since you're defining your own commands to call these environments anyway, nothing is really lost if you just define your own versions of all these environments, e.g., myproblem, mysolution, with the same labels, without this optional argument, so they each get their own counter.

\documentclass[9pt]{beamer}
\usepackage{epsfig,amsthm,subfigure,amssymb,amsmath,amsfonts}
\setbeamertemplate{theorems}[numbered]

\newtheorem{myproblem}{\translate{Problem}}
\newtheorem{mysolution}{\translate{Solution}}
\theoremstyle{definition}
\newtheorem{mydefinition}{\translate{Definition}}
\newcommand{\thi}[1]{\begin{theorem}#1 \end{theorem}}
\newcommand{\defi}[1]{\begin{mydefinition}#1 \end{mydefinition}}
\newcommand{\prob}[1]{\begin{myproblem}#1 \end{myproblem}}
\newcommand{\solu}[1]{\begin{mysolution}#1 \end{mysolution}}

\title{course 2} % The short title appears at the bottom of every slide, the full title is only on the title page

\author{John Doe} % Your name
\institute[] % Your institution as it will appear on the bottom of every slide, may be shorthand to save space
{
Department of xx \\ % Your institution for the title page
\smallskip
school name % Your email address
}
\date{}
\smallskip

\begin{document}
\maketitle
\begin{frame}
\thi{}
\prob{}
\solu{}
\defi{}
\end{frame}
\end{document}

theorem environments with their own counters

4
  • It solved my problem but just curious-- is "translate" the function that makes the problem and solution replicate each other's counter?
    – rose
    Commented Sep 6, 2022 at 5:11
  • 1
    @rose \translate makes sure that the words "Problem" etc. will be shown in the language you choose for your document (at least if it is one of the languages for which translations are available in the translator package ) Commented Sep 6, 2022 at 8:07
  • In case it wasn't clear from samcarter's comment, no, the last argument to the \newtheorem command just sets the word that is printed before the number. You could just write {Theorem} instead of {\translate{Theorem}}, but then it wouldn't change if you switched languages. What makes it use the same counter as something else is the middle optional argument which I've removed so they all get their own. If you wanted two environments to share a counter you could do, e.g., \newtheorem{question}[problem]{Question} for a "question" environment that shared its counter with "problem".
    – frabjous
    Commented Sep 6, 2022 at 14:56
  • Oh and in addition, I haven't done anything to make problem and solution match up. They each have their own counter, starting at 1. If you always have a solution for every problem right after it (and never more than one), they will end up matching up, but if you didn't, then you'd have to manually increase one of the counters to keep them in sync. (Or there are more advanced methods you could use; if you wanted help designing a more advanced method let me know.)
    – frabjous
    Commented Sep 6, 2022 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .