# Beamer Warsaw theme: Reduce the number of subsections visible in the navigation bar

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:

I want it to look like:

• 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 :)) – Sean Allred Oct 8 '14 at 14:15
• take a look at tex.stackexchange.com/questions/54950/… which seems similar to your question. – Nico Boni Oct 8 '14 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. – karl.ranseier Oct 9 '14 at 6:20
• @SeanAllred : Sorry, I added example code and pics how it looks and should look like. – karl.ranseier Oct 9 '14 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. – Nico Boni Oct 9 '14 at 7:38

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}}%
\long\def\secname{#2}%
\long\def\lastsection{#1}%
{\the\beamer@tocsectionnumber}}}%
\beamer@ifempty{#1}{}{%
}%
\beamer@sectionstartpage=\c@page%
\beamer@subsectionstartpage=\c@page%
\def\insertsubsection{}%
\def\insertsubsubsection{}%
\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}%
\gdef\prevsection{\csname section\romannumeral\theprevsection \endcsname}%
\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}%
}%
}%
\beamer@subsectionstartpage=\c@page%
\def\insertsubsubsection{}%
\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}%
\gdef\prevsubsection{\csname subsection\romannumeral\theprevsubsection \endcsname}%
\renewcommand\nextsubsection{\csname subsection\romannumeral\thenextsubsection \endcsname}%
}

{%
\leavevmode%
\@tempdimb=2.4375ex%
\ifnum\beamer@subsectionmax<\beamer@sectionmax%
\multiply\@tempdimb by\beamer@sectionmax%
\else%
\multiply\@tempdimb by\beamer@subsectionmax%
\fi%
\ifdim\@tempdimb>0pt%
\vbox to \@tempdimb{%
\ifnum\thesection=1 \else%
\vfill{\color{fg!40!bg}\prevsection}%
\fi%
\ifnum\thesection=\beamer@sectionmax \else%
\vfill{\color{fg!40!bg}\nextsection}%
\fi\vfill%
}%
\end{beamercolorbox}%
\vbox to \@tempdimb{%
\ifnum\thesubsection=1 \else%
\vfill{\color{fg!40!bg}\prevsubsection}%
\fi%
\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}


• 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) – karl.ranseier Oct 9 '14 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. – Nico Boni Oct 9 '14 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"? – karl.ranseier Oct 9 '14 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) – Nico Boni Oct 9 '14 at 13:24
• Is there an easy way to make the output an animated give? I like that solution to show the result. – karl.ranseier Oct 13 '14 at 14:26

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
{
\@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
{
\@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%%%%%%%%%%%%%%%%%%%%%%%%%%%
{%
\leavevmode%
\@tempdimb=2.4375ex%
\ifnum\beamer@subsectionmax<\beamer@sectionmax%
\multiply\@tempdimb by\beamer@sectionmax%
\else%
\multiply\@tempdimb by\beamer@subsectionmax%
\fi%
\ifdim\@tempdimb>0pt%
\vbox to \@tempdimb{%
\ifnum\thecalcmaxsec>-1\vfill{\calcsection{-3}}\fi%
\ifnum\thecalcmaxsec>-2\vfill{\calcsection{-2}}\fi%
\ifnum\thesection>1\vfill{\calcsection{-1}}\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}%
\vbox to \@tempdimb{%
\ifnum\thecalcmaxsubsec>-1 \vfill{\calcsubsection{-3}}\fi%
\ifnum\thecalcmaxsubsec>-2 \vfill{\calcsubsection{-2}}\fi%
\ifnum\thesubsection>1 \vfill{\calcsubsection{-1}}\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}