Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a counter of an environment that follows the section numbers in beamer?

I want to create a counter that enumerates the Theorem-environments and Definition- environments in a beamer presentation in such a way that the enumeration follows the section numbers (the first theorem in section 5 should be Theorem 5.1 etc.). These enumerations should be independent of one another (the first definition in section 5 should be Definition 5.1 and not Definition 5.2). Is there a way to do this?

\documentclass[9pt,trans,xcolor={table},envcountsect]{beamer} % Plain

\usefonttheme[onlymath]{serif}
\usetheme[shownavsym,right]{Aalborg}

\setbeamertemplate{section in toc}[sections numbered] % Automatic enumeration of sections
\setbeamertemplate{blocks}[rounded][shadow=true] 

\definecolor{dgreen}{rgb}{0.,0.6,0.} 
\definecolor{aaublue}{RGB}{33,26,82}% dark blue

\usepackage{etoolbox} % In order to still use an outdated beamer version

\AtBeginEnvironment{theorem}{%
\setbeamertemplate{itemize items}[circle]                    % Shape of bullet-points
\setbeamercolor{block title}{bg=dgreen!100!white,fg=white}%
\setbeamercolor{itemize item}{fg=dgreen!100!white}%
\setbeamercolor{itemize subitem}{fg=dgreen!100!white}%
\setbeamercolor{itemize subsubitem}{fg=dgreen!100!white}%
\setbeamercolor{enumerate item}{fg=dgreen!100!black}%
\setbeamercolor{enumerate subitem}{fg=dgreen!100!black}%
\setbeamercolor{enumerate subsubitem}{fg=dgreen!100!black}%
}

\AtBeginEnvironment{definition}{%
\setbeamertemplate{itemize items}[circle]                    % Shape of bullet-points
\setbeamercolor{block title}{bg=blue,fg=white}%
\setbeamercolor{itemize item}{fg=blue}%
\setbeamercolor{itemize subitem}{fg=blue}%
\setbeamercolor{itemize subsubitem}{fg=blue}%
\setbeamercolor{enumerate item}{fg=blue}%
\setbeamercolor{enumerate subitem}{fg=blue}%
\setbeamercolor{enumerate subsubitem}{fg=blue}%
}

\setbeamercolor*{block body}{bg=black!10!white,fg=black} 
\setbeamercolor*{block body alerted}{bg=normal text.bg!90!black,fg=black} 
\setbeamercolor*{block body example}{bg=normal text.bg!90!black,fg=black} 
\setbeamercolor*{block title}{parent=structure2,bg=normal text.bg!0!blue}
\setbeamercolor*{block title alerted}{use={normal text,alerted text},fg=alerted text.fg!0!white,bg=normal text.bg!10!red}
\setbeamercolor*{block title example}{use={normal text,example text},fg=white,bg=cyan}
\setbeamercolor*{block title theorem}{use={normal text,example text},fg=example text.fg!100!normal text.fg,bg=normal text.bg!0!dgreen}

\makeatletter
\pgfdeclareverticalshading[lower.bg,upper.bg]{bmb@transition}{200cm}{color(0pt)=(lower.bg); color(4pt)=(lower.bg); color(4pt)=(upper.bg)}
\makeatother

\makeatletter
\newcommand{\ShiftSectionNumber}[1]{%
\beamer@tocsectionnumber=\numexpr#1+\beamer@tocsectionnumber}
\makeatother

\setbeamertemplate{theorem begin}[normal font]

\begin{document}

\begin{frame}%[allowframebreaks]
    \frametitle{Overview}
    \tableofcontents
\end{frame}

\ShiftSectionNumber{4}
\addtocounter{section}{4} % Enumeration of theorems and examples follows section numbers

\section{Section}
\begin{frame}[<+->]{Enumeration of environments}
    \begin{theorem}[Wanted: Counter]
        \begin{itemize}
            \item Wanted: Counter that follows section numbers (Theorem 5.1)
        \end{itemize}     
    \end{theorem}
    \begin{theorem}[Wanted: Counter]
        \begin{itemize}
            \item Wanted: Counter that follows section numbers (Theorem 5.2)
        \end{itemize}     
    \end{theorem}
    \begin{definition}[Wanted: Counter]
        \begin{itemize}
            \item Wanted: Counter independent of theorem-counter: Definition 5.1
        \end{itemize}        
    \end{definition}
\end{frame}

\end{document}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

\documentclass[9pt,trans,xcolor={table},envcountsect]{beamer} % Plain

\usefonttheme[onlymath]{serif}
\usetheme[shownavsym,right]{Aalborg}

\setbeamertemplate{section in toc}[sections numbered] % Automatic enumeration of sections
\setbeamertemplate{blocks}[rounded][shadow=true] 

\definecolor{dgreen}{rgb}{0.,0.6,0.} 
\definecolor{aaublue}{RGB}{33,26,82}% dark blue

\usepackage{etoolbox} % In order to still use an outdated beamer version

\AtBeginEnvironment{theorem}{%
\setbeamertemplate{itemize items}[circle]                    % Shape of bullet-points
\setbeamercolor{block title}{bg=dgreen!100!white,fg=white}%
\setbeamercolor{itemize item}{fg=dgreen!100!white}%
\setbeamercolor{itemize subitem}{fg=dgreen!100!white}%
\setbeamercolor{itemize subsubitem}{fg=dgreen!100!white}%
\setbeamercolor{enumerate item}{fg=dgreen!100!black}%
\setbeamercolor{enumerate subitem}{fg=dgreen!100!black}%
\setbeamercolor{enumerate subsubitem}{fg=dgreen!100!black}%
}

\AtBeginEnvironment{definition}{%
\setbeamertemplate{itemize items}[circle]                    % Shape of bullet-points
\setbeamercolor{block title}{bg=blue,fg=white}%
\setbeamercolor{itemize item}{fg=blue}%
\setbeamercolor{itemize subitem}{fg=blue}%
\setbeamercolor{itemize subsubitem}{fg=blue}%
\setbeamercolor{enumerate item}{fg=blue}%
\setbeamercolor{enumerate subitem}{fg=blue}%
\setbeamercolor{enumerate subsubitem}{fg=blue}%
}

\setbeamercolor*{block body}{bg=black!10!white,fg=black} 
\setbeamercolor*{block body alerted}{bg=normal text.bg!90!black,fg=black} 
\setbeamercolor*{block body example}{bg=normal text.bg!90!black,fg=black} 
\setbeamercolor*{block title}{parent=structure2,bg=normal text.bg!0!blue}
\setbeamercolor*{block title alerted}{use={normal text,alerted text},fg=alerted text.fg!0!white,bg=normal text.bg!10!red}
\setbeamercolor*{block title example}{use={normal text,example text},fg=white,bg=cyan}
\setbeamercolor*{block title theorem}{use={normal text,example text},fg=example text.fg!100!normal text.fg,bg=normal text.bg!0!dgreen}

\makeatletter
\pgfdeclareverticalshading[lower.bg,upper.bg]{bmb@transition}{200cm}{color(0pt)=(lower.bg); color(4pt)=(lower.bg); color(4pt)=(upper.bg)}
\makeatother

\makeatletter
\newcommand{\ShiftSectionNumber}[1]{%
\beamer@tocsectionnumber=\numexpr#1+\beamer@tocsectionnumber}
\makeatother

\setbeamertemplate{theorems}[numbered]
\addtobeamertemplate{theorem begin}{\normalfont}

\let\definition\undefined
\newtheorem{definition}{\translate{Definition}}[section]


\begin{document}

\begin{frame}%[allowframebreaks]
    \frametitle{Overview}
    \tableofcontents
\end{frame}

\ShiftSectionNumber{4}
\addtocounter{section}{4} % Enumeration of theorems and examples follows section numbers



\section{Section}
\begin{frame}[<+->]{Enumeration of environments}
    \begin{theorem}[Wanted: Counter]
        \begin{itemize}
            \item Wanted: Counter that follows section numbers (Theorem 5.1)
        \end{itemize}     
    \end{theorem}
    \begin{theorem}[Wanted: Counter]
        \begin{itemize}
            \item Wanted: Counter that follows section numbers (Theorem 5.2)
        \end{itemize}     
    \end{theorem}
    \begin{definition}[Wanted: Counter]
        \begin{itemize}
            \item Wanted: Counter independent of theorem-counter: Definition 5.1
        \end{itemize}        
    \end{definition}
\end{frame}

\end{document}

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading