1

I was trying to have some standard (sub(sub))sections, where beamer would automatically create a slide dedicated to separate them, and, in other cases, a section that would appear in the pdf navigation bar and in the TOC slide, but do not create the slide separating the sections (the code that I am using for making slides separating the sections is in the end of the question). I have called this a phantom section, but if there is a better name to call it, please edit the title of the question to help others to find this question.

One approach near to the desired behavior can be found in this question, but it does not adds the hyperlink to the correct slide number in the TOC and does not add the section to the pdf navigation bar. I tried adapting its code to work with sub(sub)sections:

\makeatletter
\newcommand{\phantomsectionfortoc}[1]{%%
  \global\advance\beamer@tocsectionnumber by 1%%
  \addtocontents{toc}{\protect\beamer@sectionintoc{0}{#1}{0}{0}%%
    {\the\beamer@tocsectionnumber}}}
\makeatother
\makeatletter
\newcommand{\phantomsubsectionfortoc}[1]{%%
  \global\advance\beamer@tocsubsectionnumber by 1%%
  \addtocontents{toc}{\protect\beamer@subsectionintoc{0}{#1}{0}{0}%%
    {\the\beamer@tocsubsectionnumber}}}
\makeatother
\makeatletter
\newcommand{\phantomsubsubsectionfortoc}[1]{%%
  \global\advance\beamer@tocsubsubsectionnumber by 1%%
  \addtocontents{toc}{\protect\beamer@subsubsectionintoc{0}{#1}{0}{0}%%
    {\the\beamer@tocsubsubsectionnumber}}}
\makeatother

But it has the limitation of not working the hyperlink correctly. I would need to change the {0} inputs to point to the correct slide number. Besides, the sub(sub)section do not have any effect.


So, how would I be able to create phantom sections that would appear in TOC and in the pdf navigation bar, but do not create the separation slide?


Next I provide a starting code example. Suppose that Subsection1.2 ad Subsection2.1.1 shouldn't have a separation slide, how could that be achieved?

% Package options:
\PassOptionsToPackage{table,xcdraw}{xcolor}
\documentclass[table,svgnames,smaller,11pt]{beamer}
%% Add slide numbers
\newcommand*\oldmacro{}%%
\let\oldmacro\insertshorttitle%%
\renewcommand*\insertshorttitle{%%
   \oldmacro\hfill%%
   \insertframenumber\,/\,\inserttotalframenumber}
% For more themes, color themes and font themes, see:
\mode<presentation>
{
  \usetheme{Berlin}             % or try default, Darmstadt, Warsaw, Boadilla ...
  \usecolortheme{default}   % or try albatross, beaver, crane, ...
  \usefonttheme{serif}          % or try default, structurebold, ...
  %\usefonttheme{professionalfonts} % or try default, structurebold, ...
  %\usefonttheme{serif}             % or try default, structurebold, ...
  %\setmainfont{Helvetica}
  \setbeamertemplate{caption}[numbered]
}
%----------------------PACKAGES-|-SEGAKCAP---------------------
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{multicol}
\usepackage{chemfig}
\usepackage{etoolbox}
\usepackage{moresize}
\usepackage[percent]{overpic}
\usepackage[version=3]{mhchem}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{anyfontsize}
%---------------END-OF-PACKAGES-|-SEGAKCAP-FO-DNE--------------
\title{Report}
\author{wsfreund@wsfreund-mac.local}
\institute{ATLAS Internal}
\date{\today}
\setbeamerfont{frametitle}{size=\small}
\useinnertheme{rounded}
\useoutertheme{smoothtree}
\setbeamertemplate{headline}
{%
  \pgfuseshading{beamer@treeshade}%
  \vskip-10.25ex%
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
    leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
    \usebeamerfont{section in head/foot}%
    \insertsectionhead
  \end{beamercolorbox}
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
    \usebeamerfont{subsection in head/foot}%
    \hskip6pt\insertsubsectionhead
  \end{beamercolorbox}
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsubsection in head/foot}
    \usebeamerfont{subsection in head/foot}%
    \hskip12pt\insertsubsubsectionhead
  \end{beamercolorbox}
}
\defbeamertemplate{subsubsection in toc}{subsubsections numbered}
{\leavevmode\leftskip=3em%
 \rlap{\hskip-3em\inserttocsectionnumber.\inserttocsubsectionnumber.\inserttocsubsubsectionnumber}%
 \inserttocsubsubsection\par}
\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{subsection in toc}[subsections numbered]
\setbeamertemplate{subsubsection in toc}[subsubsections numbered]
\AtBeginSection[]{
  \frame<beamer>{
  \frametitle{Outline}
  \tableofcontents[
    sectionstyle=show/shaded,
    subsectionstyle=show/shaded/hide,
    subsubsectionstyle=show/hide/hide/hide,
    ]
 }
}
\AtBeginSubsection[]{
  \frame<beamer>{
  \frametitle{Outline}
  \tableofcontents[
    sectionstyle=show/shaded,
    subsectionstyle=show/shaded/hide,
    subsubsectionstyle=show/shaded/hide/hide
    ]
 }
}
\AtBeginSubsubsection[]{
  \frame<beamer>{
  \frametitle{Outline}
  \tableofcontents[
    sectionstyle=show/shaded,
    subsectionstyle=show/shaded/hide,
    subsubsectionstyle=show/shaded/hide/hide
    ]
 }
}
\begin{document}
%--------------------------------------------------------------
\titlepage
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\section*{Outline}
%--------------------------------------------------------------
\begin{frame}
[allowframebreaks]
\frametitle{Outline}
\tableofcontents
\end{frame}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\section{Section1}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\subsection{Subsection1.1}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide1}
\end{frame}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide2}
\end{frame}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\subsection{Subsection1.2}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide3}
\end{frame}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide4}
\end{frame}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\section{Section2}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\subsection{Subsection2.1}
%--------------------- --------- -------- ---------------------
\subsubsection{Subsection2.1.1}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide5}
\end{frame}
%--------------------- --------- -------- ---------------------
\subsubsection{Subsection2.1.2}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide6}
\end{frame}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\subsection{Subsection2.2}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide7}
\end{frame}
\end{document}
  • Can you provide a proper example people can compile? Mere code fragments aren't very useful. – cfr Sep 22 '17 at 2:09
  • Yes, the point is that when you use separation slides, it is a global property of your latex template. You can't make a beamer file with some section with separation slides and other sections without, that is what I would like to achieve. I will provide a minimal code fragment. – Werner Sep 22 '17 at 2:10
  • @cfr the example is available in the update. I have also added the desired output to help make the question clearer. – Werner Sep 22 '17 at 2:37
  • Should those phantom sections also appear in the header of your slides? Should they be recognized by the navigation symbols in the lower right? Should they work just like sections with the exception of the outline frames? Will there be more sections or more phantom sections? – Mike Sep 22 '17 at 3:18
  • @Mike if they appear in the header of the slides don't make too much of a difference, what is simpler could be implemented. Yes, they should be fully navigable, except that they don't have outline (separation) frames. More phantom sections, as I will use it specially in the subsubsections, to reduce the total number of slides. – Werner Sep 22 '17 at 6:46
3

Here the commands \outlinesection, \outlinesubsections, and \outlinesubsubsection are defined to produce a section, subsection, or subsubsection, which starts with an outline frame. Besides the outline frame, both \outlinesection and \section work exactly the same. This also applies to subsections and subsubsections.

For that, the command \outlineframe was defined, which can also be used anywhere in the presentation between frames (see between slides 3 and 4).

How it works:

It works by making \outlineframe in \AtBeginSection conditional, using \ifdooutline. \outlinesection sets \dooutlinetrue, so the outline frame is shown. At the end of \AtBeginSection \dooutlinefalse is set to switch back to the default behaviour. (Same for subsection and subsubsection.)

Note that is is important that \section is at the very end in the definition of \outlinesection. This way, \outlinesection doesn't need any parameters itself. And those following are are use by \section. Therefore \outlinesection can be used just like \section, i.e. with the same parameters. The same applies to \outlinesubsection and \outlinesubsubsection.

\PassOptionsToPackage{table,xcdraw}{xcolor}
\documentclass[table,svgnames,smaller,11pt]{beamer}
%% Add slide numbers
\newcommand*\oldmacro{}%%
\let\oldmacro\insertshorttitle%%
\renewcommand*\insertshorttitle{%%
   \oldmacro\hfill%%
   \insertframenumber\,/\,\inserttotalframenumber}
% For more themes, color themes and font themes, see:
\mode<presentation>
{
  \usetheme{Berlin}             % or try default, Darmstadt, Warsaw, Boadilla ...
  \usecolortheme{default}   % or try albatross, beaver, crane, ...
  \usefonttheme{serif}          % or try default, structurebold, ...
  %\usefonttheme{professionalfonts} % or try default, structurebold, ...
  %\usefonttheme{serif}             % or try default, structurebold, ...
  %\setmainfont{Helvetica}
  \setbeamertemplate{caption}[numbered]
}
%----------------------PACKAGES-|-SEGAKCAP---------------------
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
% commented out some packages not installed here and
% added lmodern to get rid of an error regarding fontsize
\usepackage{lmodern}
\usepackage{multicol}
%\usepackage{chemfig}
\usepackage{etoolbox}
%\usepackage{moresize}
%\usepackage[percent]{overpic}
%\usepackage[version=3]{mhchem}
\usepackage{graphicx}
\usepackage{booktabs}
%\usepackage{anyfontsize}
%---------------END-OF-PACKAGES-|-SEGAKCAP-FO-DNE--------------
\title{Report}
\author{wsfreund@wsfreund-mac.local}
\institute{ATLAS Internal}
\date{\today}
\setbeamerfont{frametitle}{size=\small}
\useinnertheme{rounded}
\useoutertheme{smoothtree}
\setbeamertemplate{headline}
{%
  \pgfuseshading{beamer@treeshade}%
  \vskip-10.25ex%
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
    leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
    \usebeamerfont{section in head/foot}%
    \insertsectionhead
  \end{beamercolorbox}
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
    \usebeamerfont{subsection in head/foot}%
    \hskip6pt\insertsubsectionhead
  \end{beamercolorbox}
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.125ex,dp=1.125ex,ignorebg,%
      leftskip=.3cm,rightskip=.3cm plus1fil]{subsubsection in head/foot}
    \usebeamerfont{subsection in head/foot}%
    \hskip12pt\insertsubsubsectionhead
  \end{beamercolorbox}
}
\defbeamertemplate{subsubsection in toc}{subsubsections numbered}
{\leavevmode\leftskip=3em%
 \rlap{\hskip-3em\inserttocsectionnumber.\inserttocsubsectionnumber.\inserttocsubsubsectionnumber}%
 \inserttocsubsubsection\par}
\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{subsection in toc}[subsections numbered]
\setbeamertemplate{subsubsection in toc}[subsubsections numbered]


\newif\ifdooutline

\newcommand{\outlineframe}{%
  \frame<beamer>{
  \frametitle{Outline}
  \tableofcontents[
    sectionstyle=show/shaded,
    subsectionstyle=show/shaded/hide,
    subsubsectionstyle=show/hide/hide/hide,
    ]
 }
}

\newcommand{\outlinesection}{\dooutlinetrue\section}
\newcommand{\outlinesubsection}{\dooutlinetrue\subsection}
\newcommand{\outlinesubsubsection}{\dooutlinetrue\subsubsection}

\AtBeginSection[]{
  \ifdooutline\outlineframe\fi
  \dooutlinefalse
}
\AtBeginSubsection[]{
  \ifdooutline\outlineframe\fi
  \dooutlinefalse
}
\AtBeginSubsubsection[]{
  \ifdooutline\outlineframe\fi
  \dooutlinefalse
}

\begin{document}
%--------------------------------------------------------------
\titlepage
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\section*{Outline}
%--------------------------------------------------------------
\begin{frame}
[allowframebreaks]
\frametitle{Outline}
\tableofcontents
\end{frame}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\section{Section1}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\subsection{Subsection1.1}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide1}
\end{frame}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide2}
\end{frame}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\outlinesubsection{Subsection1.2}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide3}
\end{frame}
%--------------------------------------------------------------
\outlineframe
\begin{frame}
\frametitle{Slide4}
\end{frame}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\outlinesection{Section2}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\subsection{Subsection2.1}
%--------------------- --------- -------- ---------------------
\subsubsection{Subsection2.1.1}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide5}
\end{frame}
%--------------------- --------- -------- ---------------------
\outlinesubsubsection{Subsection2.1.2}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide6}
\end{frame}
%--------------------- --------- -------- ---------------------
%--------------------- --------- -------- ---------------------
\outlinesubsection{Subsection2.2}
%--------------------------------------------------------------
\begin{frame}
\frametitle{Slide7}
\end{frame}
\end{document}
  • Flawless! I just added \hypersetup{bookmarksopen=true,bookmarksopenlevel=4} \setcounter{tocdepth}{4}, taken from here, to allow full navigation in the pdf TOC! – Werner Sep 23 '17 at 5:34

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.