Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm doing my presentation in beamer and I use warsaw theme. I have around 5-6 sections and they are all mentioned at the top of every page. This makes available frame space smaller. Can I limit this number by 3? For example, to show previous, current and next sections.

MWE:

\documentclass{beamer}

\mode<presentation>
{
  \setbeamertemplate{background canvas}[vertical shading][bottom=red!10,top=blue!10]

  \usetheme{Warsaw}
  \usefonttheme[onlysmall]{structurebold}
}

\begin{document}
\section{Test 1}
\begin{frame} \end{frame}
\section{Test 2}
\begin{frame} \end{frame}
\section{Test 3}
\begin{frame} \end{frame}
\section{Test 4}
\begin{frame} \end{frame}
\section{Test 5}
\begin{frame} \end{frame}

\end{document}
share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

Version 1

Hi you could alter the macro which inserts the navigation list.

    \documentclass{beamer}

    \makeatletter
    \def\insertsectionnavigation#1{%
      \hbox to #1{%
        \vbox{{\usebeamerfont{section in head/foot}\usebeamercolor[fg]{section in head/foot}%
         \vskip0.5625ex%
        \def\slideentry##1##2##3##4##5##6{}%
         \def\sectionentry##1##2##3##4##5{%
           \ifnum##5=\c@part%
           \def\insertsectionhead{##2}%
           \def\insertsectionheadnumber{##1}%
           \def\insertpartheadnumber{##5}%
           \setbox\beamer@tempbox=\hbox{%
             \hyperlink{Navigation##3}{\hbox to #1{%
                 \hskip0.3cm%
                 \ifnum\c@section=##1%
                 {\usebeamertemplate{section in head/foot}}%
                 \else%
                   {%
                   \advance\c@section by  -1 %
                     \ifnum##1 = \c@section%
                     \usebeamertemplate{section in head/foot shaded}%
                    \else%
                    \advance\c@section by  2 %
                     \ifnum##1 = \c@section%
                   \usebeamertemplate{section in head/foot shaded}%
                   \else
                   \fi
                   \fi
                   }%
                 \fi\hskip0.3cm}}}%
           \ht\beamer@tempbox=1.6875ex\dp\beamer@tempbox=0.75ex%
           \box\beamer@tempbox\fi}%
         \dohead\vskip0.5625ex}}\hfil}}
    \makeatother


      \usetheme{Warsaw}
      \usefonttheme[onlysmall]{structurebold}


    \begin{document}
    \section{Test 1}
    \begin{frame} \end{frame}
    \section{Test 2}
    \begin{frame} \end{frame}
    \section{Test 3}
    \begin{frame} \end{frame}
    \section{Test 4}
    \begin{frame} \end{frame}
    \section{Test 5}
    \begin{frame} \end{frame}

    \end{document}

Here two new conditionals are introduced, which check for the distance between the active section (stored in `\c@section`) and the printed sections. 

The result is this:

![enter image description here][1]

Version 2

This version provides a better fit to the size of three lines. Please note, that the height of the colored beamer box is adjusted manually.

\documentclass{beamer}
  \usetheme{Warsaw}
  \usefonttheme[onlysmall]{structurebold}


\makeatletter
       \newcount\c@p
       \newcount\c@m
\def\insertsectionnavigation#1{%
  \hbox to #1{%
    \vbox{{\usebeamerfont{section in head/foot}\usebeamercolor[fg]{section in head/foot}%
     \vskip0.5625ex%
    \def\slideentry##1##2##3##4##5##6{}%
     \def\sectionentry##1##2##3##4##5{%
       \ifnum##5=\c@part%
       \def\insertsectionhead{##2}%
       \def\insertsectionheadnumber{##1}%
       \def\insertpartheadnumber{##5}%
       \c@p=\c@section%
       \c@m=\c@section%
       \advance\c@m by -1 %
       \advance\c@p by 1 %
             \ifnum\c@section=##1%
               \setbox\beamer@tempbox=\hbox{%
              \hyperlink{Navigation##3}{\hbox to #1{%
             {\hskip0.3cm\usebeamertemplate{section in head/foot}\hskip0.3cm}}}}%
             \else%
                 \ifnum##1=\c@m%
                 \setbox\beamer@tempbox=\hbox{%
                  \hyperlink{Navigation##3}{\hbox to #1{%
                 {\hskip0.3cm\usebeamertemplate{section in head/foot shaded}\hskip0.3cm}}}}
                 %
                \else%
                 \ifnum##1=\c@p%
                 \setbox\beamer@tempbox=\hbox{%
                  \hyperlink{Navigation##3}{\hbox to #1{%
               {\hskip0.3cm\usebeamertemplate{section in head/foot shaded}\hskip0.3cm}}}}%
               %
               \else%
               %
               \fi%
               \fi%
               %
            \fi%%
            %

      \ht\beamer@tempbox=1.6875ex%
       \dp\beamer@tempbox=0.75ex%
       \box\beamer@tempbox\fi}%
     \dohead\vskip0.5625ex}}\hfil}}


\setbeamertemplate{headline}%{split theme} % full manual adjustment
{%
  \leavevmode%
  \@tempdimb=3em%
  \ifdim\@tempdimb>0pt%
    \advance\@tempdimb by 1.825ex%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{section in head/foot}%
      \vbox to\@tempdimb{\vfil\insertsectionnavigation{.5\paperwidth}\vfil}%
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{subsection in head/foot}%
      \vbox to\@tempdimb{\vfil\insertsubsectionnavigation{.5\paperwidth}\vfil}%
    \end{beamercolorbox}%
  \fi%
}



\makeatother

\begin{document}
\section{Test 1}
\begin{frame} \end{frame}
\section{Test 2}
\begin{frame} \end{frame}
\section{Test 3}
\begin{frame} \end{frame}
\section{Test 4}
\begin{frame} \end{frame}
\section{Test 5}
\begin{frame} \end{frame}

\end{document}

Again the if structure picks the wanted entries. But in this case the box is only filled when needed. I also introduced two helper variables c@p and c@m to avoid too complicated grouping. This renders to:

enter image description here

and the following frame will look like this:

enter image description here

Version 3

Now featuring three navigation elements at any time:

\documentclass{beamer}
  \usetheme{Warsaw}
  \usefonttheme[onlysmall]{structurebold}


\makeatletter
       \newcount\c@p
       \newcount\c@m
              \newcount\c@pp
       \newcount\c@mm
\def\insertsectionnavigation#1{%
  \hbox to #1{%
    \vbox{{\usebeamerfont{section in head/foot}\usebeamercolor[fg]{section in head/foot}%
     \vskip0.5625ex%
    \def\slideentry##1##2##3##4##5##6{}%
     \def\sectionentry##1##2##3##4##5{%
       \ifnum##5=\c@part%
       \def\insertsectionhead{##2}%
       \def\insertsectionheadnumber{##1}%
       \def\insertpartheadnumber{##5}%
       \c@p=\c@section%
       \c@m=\c@section%
      \c@pp=\c@section%
       \c@mm=\c@section%
       \advance\c@m by -1 %
       \advance\c@p by 1 %
       \advance\c@mm by -2 %
       \advance\c@pp by 2 %
       %     
       \ifnum \c@section=1
                    \ifnum\c@section=##1%
               \setbox\beamer@tempbox=\hbox{%
              \hyperlink{Navigation##3}{\hbox to #1{%
             {\hskip0.3cm\usebeamertemplate{section in head/foot}\hskip0.3cm}}}}%
             \else%
                 \ifnum##1=\c@p%
                 \setbox\beamer@tempbox=\hbox{%
                  \hyperlink{Navigation##3}{\hbox to #1{%
                 {\hskip0.3cm\usebeamertemplate{section in head/foot shaded}\hskip0.3cm}}}}
                 %
                \else%
                 \ifnum##1=\c@pp%
                 \setbox\beamer@tempbox=\hbox{%
                  \hyperlink{Navigation##3}{\hbox to #1{%
               {\hskip0.3cm\usebeamertemplate{section in head/foot shaded}\hskip0.3cm}}}}%
               %
               \else%
               %
               \fi%
               \fi%
               %
            \fi%%  
         \else%
  \ifnum \c@section=\beamer@sectionmax
               \ifnum\c@section=##1%
               \setbox\beamer@tempbox=\hbox{%
              \hyperlink{Navigation##3}{\hbox to #1{%
             {\hskip0.3cm\usebeamertemplate{section in head/foot}\hskip0.3cm}}}}%
             \else%
                 \ifnum##1=\c@m%
                 \setbox\beamer@tempbox=\hbox{%
                  \hyperlink{Navigation##3}{\hbox to #1{%
                 {\hskip0.3cm\usebeamertemplate{section in head/foot shaded}\hskip0.3cm}}}}
                 %
                \else%
                 \ifnum##1=\c@mm%
                 \setbox\beamer@tempbox=\hbox{%
                  \hyperlink{Navigation##3}{\hbox to #1{%
               {\hskip0.3cm\usebeamertemplate{section in head/foot shaded}\hskip0.3cm}}}}%
               %
               \else%
               %
               \fi%
               \fi%
               %
            \fi%%
       \else%
             \ifnum\c@section=##1%
               \setbox\beamer@tempbox=\hbox{%
              \hyperlink{Navigation##3}{\hbox to #1{%
             {\hskip0.3cm\usebeamertemplate{section in head/foot}\hskip0.3cm}}}}%
             \else%
                 \ifnum##1=\c@m%
                 \setbox\beamer@tempbox=\hbox{%
                  \hyperlink{Navigation##3}{\hbox to #1{%
                 {\hskip0.3cm\usebeamertemplate{section in head/foot shaded}\hskip0.3cm}}}}
                 %
                \else%
                 \ifnum##1=\c@p%
                 \setbox\beamer@tempbox=\hbox{%
                  \hyperlink{Navigation##3}{\hbox to #1{%
               {\hskip0.3cm\usebeamertemplate{section in head/foot shaded}\hskip0.3cm}}}}%
               %
               \else%
               %
               \fi%
               \fi%
               %
            \fi%%
            %
            \fi
            \fi
            %

      \ht\beamer@tempbox=1.6875ex%
       \dp\beamer@tempbox=0.75ex%
       \box\beamer@tempbox\fi}%
     \dohead\vskip0.5625ex}}\hfil}}


\setbeamertemplate{headline}%{split theme} % full manual adjustment
{%
  \leavevmode%
  \@tempdimb=3em%
  \ifdim\@tempdimb>0pt%
    \advance\@tempdimb by 1.825ex%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{section in head/foot}%
      \vbox to\@tempdimb{\vfil\insertsectionnavigation{.5\paperwidth}\vfil}%
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{subsection in head/foot}%
      \vbox to\@tempdimb{\vfil\insertsubsectionnavigation{.5\paperwidth}\vfil}%
    \end{beamercolorbox}%
  \fi%
}



\makeatother

\begin{document}
\section{Test 1}
\begin{frame} \end{frame}
\section{Test 2}
\begin{frame} \end{frame}
\section{Test 3}
\begin{frame} \end{frame}
\section{Test 4}
\begin{frame} \end{frame}
\section{Test 5}
\begin{frame} \end{frame}

\end{document}

It important to say that his is hard coded. This applies on 3 elements only and is not quite versatile. What it does is easy: it checks if the current frame is the first or last and inserts the navigation accordingly.

I want to add that this kind of navigation is very reader unfriendly. One has to look very carefully to understand it.

The first slide would look like this:

enter image description here

share|improve this answer
    
it's just great, thanks! I love latex, but when I need to write 60 lines of code to implement such simple request, it drives me crazy... I'm wondering if there is standard solution for this. –  damluar Feb 5 '13 at 13:36
    
I didn't write all those lines. I just altered the original definition. That makes app. 15 loc to write. A standard solution won't never exist in the world of latex. At least for such high level things like here there is always a alternative way. If you're looking for an option... well someone has to implement it. And i think (qualified) help is always wellcome ;) –  bloodworks Feb 5 '13 at 13:40
    
hello, could you tell me please how I can add 2 logo images to this customized header? I tried adding \includegraphics into \setbeamertemplate{headline}, but compilation fails.. –  damluar Mar 14 '13 at 11:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.