3

I have found a few related questions, and I'll explain below, but nothing is a true solution to this problem yet.

I would like to show the Beamer TOC under the following scenarios and only these scenarios:

  1. A new section when that section has no subsections
  2. A new section when it has a subsection but the first subsection doesn't start until at least 1 slide later and only the section will be highlighted. I do not want it to show when a subsection starts immediately (because of 3)
  3. A new subsection with the subsection highlighted

Numbers 1 and 2 don't seem to require "looking ahead". By the time AtBeginSection is triggered, we do not know yet whether there's a subsection coming up or not or where it will be.

  • yo''s answer here Beamer: TOC only once before sections with subsections does not do what I want, precisely because of the disadvantage pointed out in the answer itself "The only drawback (or feature) is that for section with subsections, in the first ToC does not "shade" the latter subsections."
  • samcarter_is_at_topanswers.xyz's answer basically will always make AtBeginSection being ineffectual. At the beginning of a new section, \insertsubsectionstartpage=\insertsectionstartpage will always be evaluated to TRUE.

I would not want an answer along the line of https://stackoverflow.com/questions/2795478/latex-beamer-prevent-showing-the-toc-at-one-occasion where we define a new command for \section to signal that this section has no subsections (manually).

I believe the answer will require looking forward to see if we can get the number of subsections in this current section and the page number of the first subsection if it exists when AtBeginSection is triggered. The TOC should only be shown in AtBeginSection when there are no subsequent subsections within the section or if the first subsection's first page is after the current page. I have no experience with getting things from the .aux or .nav files, but I believe that the relevant information should exist in those files, given that the full TOC is populated at every trigger.

Would appreciate any help here!

Code snippet:

\AtBeginSection[]{ %I want to add a condition here such that this is only when this current section has no subsections within it OR the subsection does not start right away
  \addtocounter{framenumber}{-1}
  \begin{frame}
      \frametitle{Roadmap}
      \tableofcontents[currentsection,subsectionstyle=shaded/shaded/hide]
  \end{frame}
}

\AtBeginSubsection[]{
  \addtocounter{framenumber}{-1}
  \begin{frame}
      \frametitle{Roadmap}
      \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}

MWE:

\documentclass{beamer}

\AtBeginSection[]{ %I want to add a condition here such that this is only when this current section has no subsections within it OR the subsection does not start right away
  \addtocounter{framenumber}{-1}
  \begin{frame}
      \frametitle{Roadmap}
      \tableofcontents[currentsection,subsectionstyle=shaded/shaded/hide]
  \end{frame}
}

\AtBeginSubsection[]{
  \addtocounter{framenumber}{-1}
  \begin{frame}
      \frametitle{Roadmap}
      \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}

\begin{document}

\section{section without subsections}
\begin{frame}
    slide 1
\end{frame}

\section{section with subsection starting right away}
\subsection{subsection at the beginning of section}
\begin{frame}
    slide 2
\end{frame}

\subsection{second subsection}
\begin{frame}
  slide 3
\end{frame}

\section{section with subsection starting later}
\begin{frame}
    slide 4
\end{frame}

\subsection{first subsection after a slide}
\begin{frame}
    slide 5
\end{frame}

\end{document}

EDIT: I found this other answer Show TOC in Beamer under special conditions. It uses the package xcntperchap to solve number 1. But number 2 is still not addressed. Note also that the documentation of xcntperchap says it doesn't work with Beamer. However, the example in that answer can be made to work after correcting for this issue from January 2020 Error with xassoccnt - LaTeX3 \c_one deprecated

0

You must log in to answer this question.

Browse other questions tagged .