10

My presentation consist of multiple sections. Some sections consist of subsection and some not. I want beamer to display the TOC before every subsection and before every section which consists of no other subsection.

Currently, i write in the preamble:

\AtBeginSection[] {
    \begin{frame}<beamer>
    \frametitle{Inhalt} %
    \tableofcontents[currentsection]  
    \end{frame}
}

\AtBeginSubsection[] {
    \begin{frame}<beamer>
    \frametitle{Inhalt} %
    \tableofcontents[currentsubsection]  
    \end{frame}
}

As a result, if a section consist of subsecitons beamer displays the TOC twice before the first subsection in a section, one time for the section and one time for the subsection. That is ugly in my opinion. What can i do?

9

You can very simply use TeX conditionals. The only drawback (or feature) is that for section with subsections, in the first ToC does not "shade" the latter subsections. Basically, we tell LaTeX: At section, make ToC and remember false. At subsection, if you see true make ToC, and remember true.

\documentclass{beamer}

\newif\iflattersubsect

\AtBeginSection[] {
    \begin{frame}<beamer>
    \frametitle{Inhalt} %
    \tableofcontents[currentsection]  
    \end{frame}
    \lattersubsectfalse
}

\AtBeginSubsection[] {
    \iflattersubsect
    \begin{frame}<beamer>
    \frametitle{Inhalt} %
    \tableofcontents[currentsubsection]  
    \end{frame}
    \fi
    \lattersubsecttrue
}

\title{TITLE}
\author{AUTHOR}

\begin{document}

\begin{frame}\maketitle\end{frame}

\section{SECT I}
\subsection{I.1}
\begin{frame}I.1\end{frame}

\subsection{I.2}
\begin{frame}I.2\end{frame}

\section{SECT II}
\begin{frame}II frame 1\end{frame}
\begin{frame}II frame 2\end{frame}

\section{SECT III}
\subsection{III.1}
\begin{frame}III.1\end{frame}

\subsection{III.2}
\begin{frame}III.2\end{frame}

\end{document}
1

A simple test could check if the sectionstartpage equals the subsectionstartpage and act accordingly. The following example will in this case hide the toc of the section, but hiding the subsection toc would work in the same way.

\documentclass{beamer}

\AtBeginSection[] {
    \ifnum\insertsubsectionstartpage=\insertsectionstartpage
        \relax%
    \else%
      \begin{frame}<beamer>
      \frametitle{Inhalt} %
      \tableofcontents[currentsection]  
      \end{frame}
  \fi%
}

\AtBeginSubsection[] {
    \begin{frame}<beamer>
    \frametitle{Inhalt} %
    \tableofcontents[currentsubsection]  
    \end{frame}
}

\title{TITLE}
\author{AUTHOR}

\begin{document}

\begin{frame}\maketitle\end{frame}

\section{SECT I}
\subsection{I.1}
\begin{frame}I.1\end{frame}

\subsection{I.2}
\begin{frame}I.2\end{frame}

\section{SECT II}
\begin{frame}II frame 1\end{frame}
\begin{frame}II frame 2\end{frame}

\section{SECT III}
\subsection{III.1}
\begin{frame}III.1\end{frame}

\subsection{III.2}
\begin{frame}III.2\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.