4

I give a lecture with 10 sections and maybe 5-10 subsections. Using the Warsaw theme would make the available space too small.

Is there a way to make the navigation bar show:

  • only the last section, current section and the next two sections?
  • only the last subsection, current subsection and the next two subsections?

If there is not an option, one may have to change the \insertsubsectionnavigation-function.

Maybe something like

\insertsubsectionnavigation["\thissectionnumber-1" to "\thissectionnumber+2"] 

The problem is: I don't understand the way this function works.

Does anyone have an idea or a link to a similar topic?

Here is an example of how it should NOT look:

\documentclass{beamer}
\usetheme{Warsaw}
\begin{document}
    \section{Section 1}
    \section{Section 2}
    \section{Section 3}
    \section{Section 4}
        \subsection{SubSection a}\begin{frame}Test\end{frame}
        \subsection{SubSection b}\begin{frame}Test\end{frame}
        \subsection{SubSection c}\begin{frame}Test\end{frame}
        \subsection{SubSection d}\begin{frame}Test\end{frame}
        \subsection{SubSection e}\begin{frame}Test\end{frame}
        \subsection{SubSection f}\begin{frame}Test\end{frame}
        \subsection{SubSection g}\begin{frame}Test\end{frame}
        \subsection{SubSection h}\begin{frame}Test\end{frame}
        \subsection{SubSection i}\begin{frame}Test\end{frame}
    \section{Section 5}
    \section{Section 6}
    \section{Section 7}\begin{frame}Test\end{frame}
\end{document}

A slide would look like: normal style

I want it to look like: enter image description here

5
  • 1
    Can you provide an example slide with the content you'd like to fit? (This sort of thing is called a minimal working example (MWE) and is sort of standard around here :)) Oct 8, 2014 at 14:15
  • 2
    take a look at tex.stackexchange.com/questions/54950/… which seems similar to your question.
    – Old Nick
    Oct 8, 2014 at 14:24
  • @dcmst Thanks, that's the right topic. I will try to understand it and make ot to do the same for subsections. Oct 9, 2014 at 6:20
  • @SeanAllred : Sorry, I added example code and pics how it looks and should look like. Oct 9, 2014 at 6:49
  • @karl.ranseier I didn't notice at first you wanted to do it also for subsections. I've adapted the linked answer for your use case.
    – Old Nick
    Oct 9, 2014 at 7:38

2 Answers 2

5

This is an extension of @GonzaloMedina answer from Only 3 items in navigation bar, is that possible? that covers subsections too (long Beamer code follows).

\documentclass{beamer}
\usetheme{Warsaw}

\newcounter{prevsection}
\newcounter{nextsection}
\newcounter{prevsubsection}
\newcounter{nextsubsection}


\newcommand\prevsection{}
\newcommand\nextsection{}
\newcommand\prevsubsection{}
\newcommand\nextsubsection{}

\makeatletter
\long\def\beamer@section[#1]#2{%
  \beamer@savemode%
    \mode<all>%
  \ifbeamer@inlecture%
   \refstepcounter{section}%
    \beamer@ifempty{#2}%
    {\long\def\secname{#1}\long\def\lastsection{#1}}%
    {\global\advance\beamer@tocsectionnumber by 1\relax%
      \long\def\secname{#2}%
      \long\def\lastsection{#1}%
      \addtocontents{toc}{\protect\beamer@sectionintoc{\the\c@section}{#2}{\the\c@page}{\the\c@part}%
        {\the\beamer@tocsectionnumber}}}%
    {\let\\=\relax\xdef\sectionlink{{Navigation\the\c@page}{\noexpand\secname}}}%
    \beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
    \beamer@ifempty{#1}{}{%
      \addtocontents{nav}{\protect\headcommand{\protect\sectionentry{\the\c@section}{#1}{\the\c@page}{\secname}{\the\c@part}}}%
      \addtocontents{nav}{\protect\headcommand{\protect\beamer@sectionpages{\the\beamer@sectionstartpage}{\the\beamer@tempcount}}}%
      \addtocontents{nav}{\protect\headcommand{\protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\the\beamer@tempcount}}}%
    }%
    \beamer@sectionstartpage=\c@page%
    \beamer@subsectionstartpage=\c@page%
    \def\insertsection{\expandafter\hyperlink\sectionlink}%
    \def\insertsubsection{}%
    \def\insertsubsubsection{}%
    \def\insertsectionhead{\hyperlink{Navigation\the\c@page}{#1}}%
    \def\insertsubsectionhead{}%
    \def\insertsubsubsectionhead{}%
    \def\lastsubsection{}%
    \Hy@writebookmark{\the\c@section}{\secname}{Outline\the\c@part.\the\c@section}{2}{toc}%
    \hyper@anchorstart{Outline\the\c@part.\the\c@section}\hyper@anchorend%
    \beamer@ifempty{#2}{\beamer@atbeginsections}{\beamer@atbeginsection}%
  \fi%
  \beamer@resumemode
    \setcounter{prevsection}{\thesection}%
    \setcounter{nextsection}{\thesection}%
    \addtocounter{prevsection}{-1}%
    \gdef\prevsection{\csname section\romannumeral\theprevsection \endcsname}%
     \addtocounter{nextsection}{1}%
    \renewcommand\nextsection{\csname section\romannumeral\thenextsection \endcsname}%
}%

\def\beamer@subsection[#1]#2{%
  \beamer@savemode%
  \mode<all>%
  \ifbeamer@inlecture%
    \refstepcounter{subsection}%
    \beamer@ifempty{#2}{\long\def\subsecname{#1}\long\def\lastsubsection{#1}}
    {%
      \long\def\subsecname{#2}%
      \long\def\lastsubsection{#1}%
      \addtocontents{toc}{\protect\beamer@subsectionintoc{\the\c@section}{\the\c@subsection}{#2}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}%
    }%
    \beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
    \addtocontents{nav}{%
      \protect\headcommand{\protect\beamer@subsectionentry{\the\c@part}{\the\c@section}{\the\c@subsection}{\the\c@page}{\lastsubsection}}%
      \protect\headcommand{\protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\the\beamer@tempcount}}%
    }%
    \beamer@subsectionstartpage=\c@page%
    \edef\subsectionlink{{Navigation\the\c@page}{\noexpand\subsecname}}%
    \def\insertsubsection{\expandafter\hyperlink\subsectionlink}%
    \def\insertsubsubsection{}%
    \def\insertsubsectionhead{\hyperlink{Navigation\the\c@page}{#1}}%
    \def\insertsubsubsectionhead{}%
    \Hy@writebookmark{\the\c@subsection}{#2}{Outline\the\c@part.\the\c@section.\the\c@subsection.\the\c@page}{3}{toc}%
    \hyper@anchorstart{Outline\the\c@part.\the\c@section.\the\c@subsection.\the\c@page}\hyper@anchorend%
    \beamer@ifempty{#2}{\beamer@atbeginsubsections}{\beamer@atbeginsubsection}%
  \fi%
  \beamer@resumemode
  \setcounter{prevsubsection}{\thesubsection}%
    \setcounter{nextsubsection}{\thesubsection}%
    \addtocounter{prevsubsection}{-1}%
    \gdef\prevsubsection{\csname subsection\romannumeral\theprevsubsection \endcsname}%
     \addtocounter{nextsubsection}{1}%
    \renewcommand\nextsubsection{\csname subsection\romannumeral\thenextsubsection \endcsname}%
}

\setbeamertemplate{headline}
{%
  \leavevmode%
  \@tempdimb=2.4375ex%
  \ifnum\beamer@subsectionmax<\beamer@sectionmax%
    \multiply\@tempdimb by\beamer@sectionmax%
  \else%
    \multiply\@tempdimb by\beamer@subsectionmax%
  \fi%
  \ifdim\@tempdimb>0pt%
    \advance\@tempdimb by 1.125ex%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb,right,rightskip=1em]{section in head/foot}%
      \vbox to \@tempdimb{%
      \ifnum\thesection=1 \else%
        \vfill{\color{fg!40!bg}\prevsection}%
      \fi%
        \vfill\insertsectionhead%
      \ifnum\thesection=\beamer@sectionmax \else%
        \vfill{\color{fg!40!bg}\nextsection}%
     \fi\vfill%
    }%
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{subsection in head/foot}%
      \vbox to \@tempdimb{%
      \ifnum\thesubsection=1 \else%
        \vfill{\color{fg!40!bg}\prevsubsection}%
      \fi%
        \vfill\insertsubsectionhead%
      \ifnum\thesubsection=\beamer@subsectionmax \else%
        \vfill{\color{fg!40!bg}\nextsubsection}%
     \fi\vfill%
     }%
    \end{beamercolorbox}%
  \fi%
}%
\makeatother

% Here you put the names that will go in the navigation bar
\newcommand\sectioni{test one}
\newcommand\sectionii{test two}
\newcommand\sectioniii{test three}
\newcommand\sectioniv{test four}

\newcommand\subsectioni{sub 1}
\newcommand\subsectionii{sub 2}
\newcommand\subsectioniii{sub 3}
\newcommand\subsectioniv{sub 4}

\begin{document}
\section{test one}
\begin{frame}test\end{frame}

\section{test two}
\begin{frame}test\end{frame}

\section{test three}
\begin{frame}test\end{frame}

\section{test four}
\subsection{sub 1}
\begin{frame}test\end{frame}
\subsection{sub 2}
\begin{frame}test\end{frame}
\subsection{sub 3}
\begin{frame}test\end{frame}
\subsection{sub 4}
\begin{frame}test\end{frame}

\end{document}

enter image description here

6
  • Ok, that looks ok. Thanks for that code. If I understand correctly, I have to enter my section and subsection titles twice, ones in the normal way and once in the header. Am I right? I do not understand why this is necessary. If this could be changed, I would try to add additionally \nexnextsection and \nextnextsubsection (which should be straight forwrd) Oct 9, 2014 at 8:26
  • @karl.ranseier That is the only shortcoming of this approach. If you do not set the names only the active subsection will appear in the headline. They are needed to print the not-active subsections. Notice also that you have to renew the various\subsection{} macros for every new section if the subsection names are different and the the various \section{} macros for every part.
    – Old Nick
    Oct 9, 2014 at 8:35
  • I borrowed some code from here: tex.stackexchange.com/questions/37426/… I will write a real answer, not enough space. P.S.: Where may I switch of the "send when pressing ENTER"? Oct 9, 2014 at 13:22
  • @karl.ranseier Cool! You should add your version as an answer then, it may help someone with a similar problem. (I don't know if it is possible to switch it off)
    – Old Nick
    Oct 9, 2014 at 13:24
  • Is there an easy way to make the output an animated give? I like that solution to show the result. Oct 13, 2014 at 14:26
2

The finished code follows below. At first i have renewed the \section and \subsection to add automated references. I created the funktion \calcsubsection[i] an \calcsection[i] to get the name of the section "sectionnumber+i" or "subsectionnumber+i", where i is positive for future sections, and i negative for older sections. e.g.: \calcsubsection{-1} gives the name of the previous subsectionname in the current section. \calcsubsection{1} gives the next subsectionname in the current section.

I have to start the lecture tomorrow, therefore I will now work with this solution. I would be happy if someone gives comments on improving - the code - the layout when less subsections than section appear

It really took me long time to create this code, because I never really used "this part of latex". Sorry for the old "answers", which were no answers as wanted in this forum. I deleted them.

\documentclass{beamer}
\usetheme{Warsaw}
\makeatletter
% A new section definition to automatically set labels with the name: sec:sectionnumber
\let\oldsection\section
\renewcommand{\section}[1]{\oldsection{#1}\label{sec:\thesection}}
% A new subsection definition to automatically set labels with the name: sec:sectionnumber.subsectionnumer
\let\oldsubsection\subsection
\renewcommand{\subsection}[1]{\oldsubsection{#1}\label{sec:\thesection.\thesubsection}}
%init some calculators
\newcounter{calculator}
\newcounter{calcmaxsec}
\newcounter{calcmaxsubsec}
\newcommand{\calcsubsection}[1]%procedure to get the name of section thissection+i
{
    \setcounter{calculator}{\thesubsection}\addtocounter{calculator}{#1}
    \@ifundefined{r@sec:\thesection.\thecalculator}{}{\color{fg!40!bg}\nameref{sec:\thesection.\thecalculator}}
}
\newcommand{\calcsection}[1]%procedure to get the name of subsection thissection.thissubsection+i
{
    \setcounter{calculator}{\thesection}\addtocounter{calculator}{#1}
    \@ifundefined{r@sec:\thesection}{}{\color{fg!40!bg}\nameref{sec:\thecalculator}}
}
\newcommand{\Testframe}%some testframe definition
    {
        \begin{frame}
            The Section: \thesection\\
            The Subsection: \thesubsection\\
            The Calculator: \thecalculator\\
            Count\thesection
        \end{frame}
    }
%Defining the layout%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setbeamertemplate{headline}
{%
  \leavevmode%
  \@tempdimb=2.4375ex%
  \ifnum\beamer@subsectionmax<\beamer@sectionmax%
     \multiply\@tempdimb by\beamer@sectionmax%
  \else%
     \multiply\@tempdimb by\beamer@subsectionmax%
  \fi%
  \ifdim\@tempdimb>0pt%
     \advance\@tempdimb by 1.125ex%
     \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb,right,rightskip=1em]{section in head/foot}%
        \vbox to \@tempdimb{%
        \setcounter{calcmaxsec}{\thesection}\addtocounter{calcmaxsec}{-\beamer@sectionmax}
        \ifnum\thecalcmaxsec>-1\vfill{\calcsection{-3}}\fi%
        \ifnum\thecalcmaxsec>-2\vfill{\calcsection{-2}}\fi%
        \ifnum\thesection>1\vfill{\calcsection{-1}}\fi%
        \ifnum\thesection>0\vfill\insertsectionhead\fi
        \ifnum\thecalcmaxsec<0\vfill{\calcsection{1}}\fi
        \ifnum\thecalcmaxsec<-1\vfill{\calcsection{2}}\fi
        \ifnum\thesection<2\vfill{\calcsection{3}}\fi
        \ifnum\thesection<1\vfill{\calcsection{4}}\fi
        \vfill%
     }%
     \end{beamercolorbox}%
     \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{subsection in head/foot}%
        \vbox to \@tempdimb{%
        \setcounter{calcmaxsubsec}{\thesubsection}\addtocounter{calcmaxsubsec}{-\beamer@subsectionmax}
        \ifnum\thecalcmaxsubsec>-1 \vfill{\calcsubsection{-3}}\fi%
        \ifnum\thecalcmaxsubsec>-2 \vfill{\calcsubsection{-2}}\fi%
        \ifnum\thesubsection>1 \vfill{\calcsubsection{-1}}\fi%
        \ifnum\thesubsection>0 \vfill\insertsubsectionhead\fi
        \ifnum\beamer@subsectionmax>1{\ifnum\thecalcmaxsubsec<0\vfill{\calcsubsection{1}}\fi}\fi
        \ifnum\beamer@subsectionmax>2{\ifnum\thecalcmaxsubsec<-1\vfill{\calcsubsection{2}}\fi}\fi
        \ifnum\beamer@subsectionmax>3{\ifnum\thesubsection<2\vfill{\calcsubsection{3}}\fi}\fi
        \ifnum\beamer@subsectionmax>4{\ifnum\thesubsection<1\vfill{\calcsubsection{4}}\fi}\fi
        \vfill%
      }%
     \end{beamercolorbox}%
  \fi%
}%
\makeatother %%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{test one}\Testframe
    \subsection{sub 1}\Testframe
    \subsection{sub 2}\Testframe
    \subsection{sub 3}\Testframe
    \subsection{sub 4}\Testframe
    \subsection{sub 5}\Testframe
    \subsection{sub 6}\Testframe
    \subsection{sub 7}\Testframe
\section{test two}\Testframe
    \subsection{sub 1}\Testframe
    \subsection{sub 2}\Testframe
\section{test three}\Testframe
    \subsection{sub 1}\Testframe
    \subsection{sub 2}\Testframe
    \subsection{sub 3}\Testframe
\section{test four}\Testframe
    \subsection{sub 1}\Testframe
    \subsection{sub 2}\Testframe
    \subsection{sub 3}\Testframe
    \subsection{sub 4}\Testframe
\section{test five}\Testframe
    \subsection{sub 1}\Testframe
\section{test six}\Testframe
    \subsection{sub 1}\Testframe
\end{document}
1
  • In the above MWE, instead of 4 (the previous, present, and the next two) sections and subsections, what and where should I do the modification(s) to show 3 (the previous, present and the next) sections and subsections?
    – Kiran K U
    Jun 22, 2020 at 16:27

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.