[Tex/LaTex] Customizing the navigation sidebar “per section”

beamernavigation

I'm looking for a command to remove at will the first or the last X items of the TOC displayed in the sidebar.

My problem appear when there is too many items in the sidebar. For example, the above picture shows a small sidebar.

Small navigation sidebar

But, later in my presentation (see above), I will display so many subsections that the last TOC item disappear (and TeX issues an overfull vbox…)

Overfull navigation sidebar

Ideally, I'm wanting some advice in order to write some macro that will remove the 1 or 2 first TOC items (here Sommaire and Objectifs pédagogiques) when I am in the problematic section (Méthode …).

I already check this question that is a little similar, but it does not solve my problem as there are always only 3 section displayed.

Best Answer

For information, here is what I have done to solve my problem

1/ I have defined a couple of counters

\newcounter{numsection}  % count the index of the sections
\newcounter{skipsection} % number of the section to remove at the beginning
\newcounter{lastsection} % index of the last section to display
\def\tmp@skipsection{0}  % temporary variable
\def\tmp@lastsection{0}  % temporary variable

2/ Definition of the function to set the counters; they have to be called before the \section command

\newcommand{\setskipsection}[1]{\gdef\tmp@skipsection{#1}}
\newcommand{\setlastsection}[1]{\gdef\tmp@lastsection{#1}}

3/ Installation of the hooks using \AtBeginSection command:

\AtBeginSection[]{
    \setcounter{skipsection}{\tmp@skipsection}
    \setcounter{lastsection}{\tmp@lastsection}
    \setskipsection{0}
    \setlastsection{0}
    \sectionframe
}

4/ Redefinition of the relevant template: a) reset the counter for the section index

\defbeamertemplate*{sidebar left}{modele-name}
{%
    \setcounter{numsection}{0}%
    \insertverticalnavigation{\beamer@leftsidebar}%
}

b) code for a normal section, essentially to count the index of the section

\defbeamertemplate*{section in sidebar}{modele-name}
{%
    \stepcounter{numsection}%
    \ifnum\value{numsection}>\value{skipsection}%
        % code for typesetting section name
    \fi%
}

c) code for a shaded section

\defbeamertemplate*{section in sidebar shaded}{modele-name}
{%
    \stepcounter{numsection}%
    \ifnum\value{lastsection}=0%
        \ifnum\value{numsection}=\value{skipsection}%
            % code to display the *collapsed* sections at the beginning of the sidebar
        \fi%
        \ifnum\value{numsection}>\value{skipsection}%
            % code to display a normal shaded section
        \fi%
    \else%
        \ifnum\value{numsection}=\value{skipsection}%
            % code to display the *collapsed* sections at the beginning of the sidebar
        \fi%
        \ifnum\value{numsection}>\value{skipsection}%
            \ifnum\value{numsection}<\value{lastsection}%
                % code to display a normal shaded section
            \fi%
            \ifnum\value{numsection}=\value{lastsection}%
                % code to display the *collapsed* sections at the end of the sidebar
            \fi%
        \fi%
    \fi%
}