6

I'm trying to define a custom theme for beamer. I would like to have a horizontal list of all sections but with a character between them. What I have is:

\setbeamertemplate{headline}[text line]{\insertsectionnavigationhorizontal{\paperwidth}{}{}}

And what I would like to see is something like:

Section1 | Section2 | Section3 | Section4

Is that possible?

7

Yes, it is possible; not trivial, but possible:

(I will add some explanation when I have time)

\documentclass{beamer}
\usepackage{totcount}
\usepackage{tikz}

\regtotcounter{section}
\newcounter{vertrules}

\setbeamercolor{section in head/foot}{fg=green!40!black}
\setbeamercolor*{frametitle}{fg=green!40!black}
\setbeamercolor{myheadline}{fg=green!40!black,bg=green!10}

\setbeamertemplate{headline}
{%
  \begin{beamercolorbox}[wd=\paperwidth]{myheadline}
    \vskip1.5ex%
    \insertsectionnavigationhorizontal{\paperwidth}{\hskip0pt}{\hskip-12pt}\vskip2pt
  \end{beamercolorbox}%
  \setcounter{vertrules}{\totvalue{section}}
  \ifnum\thevertrules<2 \else
  \addtocounter{vertrules}{-1}
  \begin{tikzpicture}[remember picture,overlay]
  \foreach \i in {1,2,...,\thevertrules}
  \draw[ultra thick,green!40!black] (\i*\sectionboxwd+0.5\i,0) -- (\i*\sectionboxwd+0.5\i,1);
  \end{tikzpicture}%
  \fi%
}

\setbeamertemplate{section in head/foot}{%
    \hspace*{-6pt}\setlength\fboxsep{0pt}%
    \parbox[c][4ex][t]{\dimexpr\sectionboxwd-5pt\relax}{%
      \hfill\parbox{\dimexpr\sectionboxwd-12pt\relax}{%
      \raggedright\insertsectionhead%
      }\hfill\mbox{}%
    }\hspace*{6pt}%
}

\newlength\sectionboxwd

\AtBeginDocument{%
  \ifnum\totvalue{section}>0 
    \setlength\sectionboxwd{\dimexpr\paperwidth/\totvalue{section}\relax}
  \else
    \setlength\sectionboxwd{\paperwidth}
  \fi
} 

\begin{document}

\section{Test Section One with a really long title}
\begin{frame}\frametitle{Test frame one}test\end{frame}
\section{Test Section Two}
\begin{frame}\frametitle{Test frame two}test\end{frame}
\section{Test Section Three}
\begin{frame}\frametitle{Test frame three}test\end{frame}
\section{Test Section Four}
\begin{frame}\frametitle{Test frame four}test\end{frame}

\end{document}

And some images showing the result with the vertical rules:

enter image description here

enter image description here

enter image description here

enter image description here

  • Thanks for your help! That's nearly what I was looking for, can you give me a hint how to modify that code to have everything left aligned? ---------------------------------------------- Section1 | Section2 | Section3 ---------------------------------------------- And maybe how to replace the line with a character. Thanks in advance! If that's not possible or too complex, don't mind :) – Bertram Nudelbach Jun 5 '12 at 7:40
  • Oh dear, I'm not able to format that comment correct. What I mean is, that the sections have only the minimal width required for showing the text. Although this might have the result that not all sections were shown if too much sections are defined (as with normal \insertsectionnavigationhorizontal). – Bertram Nudelbach Jun 5 '12 at 7:49
1

So I played around a bit with the solution provided by Gonzola Medina and here is what I wanted to have - thanks again!

\setbeamertemplate{section in head/foot shaded}{%  
\color{white}\insertsectionhead\ \ \ \ |  
}  

\setbeamertemplate{section in head/foot}{%  
\insertsectionhead\color{white}\ \ \ \ |  
}  

\setbeamertemplate{headline}{%  
\begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex]{myheadline}  
\Tiny\hspace*{4mm} {\hspace*{2ex}\color{white}|\hspace*{-2ex}}\insertsectionnavigationhorizontal{0ex}{}{}  
\end{beamercolorbox}%  
}

It prints all sections and places | between them. The color white is because it should be white for my color scheme.

The only thing I don't know is how to change the margin/padding of each section. You can see the trailing spaces I added. I did this to have the same space before and after each section.

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.