3

I want to automate the creation of titles in beamer such that an environment Frame sets the title to this pattern

<current-section> (<frame-number>)

where <current-section> is the title of the current section (including subsection or subsubsection) and <frame-number> is the number of the frame within the current section (not the total number of frames).

Here's a MWE:

\documentclass{beamer}

% includes

\usepackage{ifthen}

% commands

\newcommand{\CurrentSectionTitle}{%
\ifthenelse{%
    \equal{\insertsubsubsectionhead}{}%
}%
{%
    (...)
}%
{\insertsubsubsectionhead}%
}

\newenvironment{Frame}%
{%
    \begin{frame}
        \frametitle{\CurrentSectionTitle (\insertframenumber)}
}%
{%
    \end{frame}
}%

\title{Test}
\author{}
\date{\today}

\begin{document}

\frame{\titlepage}

\frame{
\frametitle{Table Of Contents}
\tableofcontents
}

\section{A}

\subsection{A.1}

\begin{Frame}
\begin{itemize}
    \item a
    \item b
\end{itemize}   
\end{Frame}

\begin{Frame}
\begin{itemize}
    \item c
    \item d
\end{itemize}   
\end{Frame}

\end{document}

I was running into trouble getting the current section title using \ifthenelse and don't know how to get the number of the current frame witin the current section.

Any ideas, pointers?

2

One possibility is to redefine the section and subsection commands such that the current title is stored to a global definition (well, bad code so far ;-))

Afterwards, it is checked, whether the subsection number is greater then zero, if so, the subsection title is included, otherwise the section title.

This could be further worked out, especially the toc entries are wrong so far.

It would also be finer code, to redefine the frame environment instead of using Frame.

\documentclass{beamer}

% includes

\usepackage{blindtext}
\usepackage{etoolbox}


\let\LaTeXStandardSection\section
\let\LaTeXStandardSubsection\subsection

\def\CurrentSectionTitle{}%    Two dummy defs
\def\CurrentSubsectionTitle{}%

\makeatletter
\@addtoreset{subsection}{section}
\@addtoreset{framenumber}{section}

\newrobustcmd{\section@noopt}[1]{%
\gdef\CurrentSectionTitle{#1}%
\LaTeXStandardSection{#1}%
}%

\newrobustcmd{\section@opt}[2][]{%
\gdef\CurrentSectionTitle{#2}%
\LaTeXStandardSection[#1]{#2}%
}%



\renewcommand{\section}{%
\@ifnextchar[{\section@opt}{\section@noopt}%
}%


\newrobustcmd{\subsection@noopt}[1]{%
\gdef\CurrentSubsectionTitle{#1}%
\LaTeXStandardSubsection{#1}%
}%


\newrobustcmd{\subsection@opt}[2][]{%
\gdef\CurrentSubsectionTitle{#2}%
\LaTeXStandardSubsection[#1]{#2}%
}%

\renewcommand{\subsection}{%
\@ifnextchar[{\subsection@opt}{\subsection@noopt}%
}%


\makeatother

\newrobustcmd{\CheckWhichTitleToUse}{%
\ifnumgreater{\number\value{subsection}}{0}{\CurrentSubsectionTitle}{\CurrentSectionTitle}%
}%



% commands


\renewcommand{\theframenumber}{-- Frame \arabic{framenumber}}

\newenvironment{Frame}{%
\begin{frame}{\CheckWhichTitleToUse~\theframenumber}%
}{%
\end{frame}%  End code of environment
}% End of newenvironment

\title{Test}
\author{}
\date{\today}

\begin{document}

\frame{\titlepage}

\frame{%
\frametitle{Table Of Contents}
\tableofcontents
}

\section{A}

% No subsection

\begin{Frame}
\begin{itemize}
    \item a
    \item b
\end{itemize}   
\end{Frame}


\subsection{A.1}

\begin{Frame}
\begin{itemize}
    \item a
    \item b
\end{itemize}   
\end{Frame}

\begin{Frame}
\begin{itemize}
    \item c
    \item d
\end{itemize}   
\end{Frame}

\section{Another Section}



\begin{Frame}
\begin{itemize}
    \item<1-2> e
    \item<2-2> f
\end{itemize}   
\end{Frame}

\begin{Frame}
\blindtext
\end{Frame}


\end{document}

Frame with section title Frame with subsection title

  • @FK82: Ok, please change the \theframenumber command at will, I just introduced the style in order to make it more outstanding for demonstration, but not for production – user31729 May 29 '14 at 13:31
  • I will have to go through this step by step first ;) I'm pretty new to how TeX/LaTeX works under the hood. – FK82 May 29 '14 at 13:38
  • I readily explain it to you in chat, if you prefer that? – user31729 May 29 '14 at 13:39
  • I'll get back to you on that. Thanks for the offer! – FK82 May 29 '14 at 13:44
  • @FK82: You're welcome... I love to convince others of the dark side (LaTeX) ;-) – user31729 May 29 '14 at 13:46

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.