0

I want a textline that shows all section titles in gray and the current section highlighted e.g. in black or boldprint as here:

title of sec1 | title of sec2 | tilte of sec3 | title of sec4

So far I've come to this point

\documentclass{beamer}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{totcount}       
\regtotcounter{section}             % total amount of sections

\begin{document}

\begin{frame}
  \section{First section} \label{sec:first_section}
    \foreach \x in {1,...,\totvalue{section}}{
            \ifnum\x=1
                \ifnum\x=\value{section}
                    \textcolor{black}{\insertsection}
                 \else
                    \textcolor{gray}{\insertsection}
                 \fi 
            \else
                \ifnum\x=\value{section}
                    | \textcolor{black}{\insertsection}
                 \else
                    | \textcolor{gray}{\insertsection}
                \fi
            \fi}
            \\
            Text of first section.\\
            \vspace{2mm}

  \section{Second section} \label{sec:second_section}
    \foreach \x in {1,...,\totvalue{section}}{
            \ifnum\x=1
                \ifnum\x=\value{section}
                    \textcolor{black}{\insertsection}
                 \else
                    \textcolor{gray}{\insertsection}
                 \fi 
            \else
                \ifnum\x=\value{section}
                    | \textcolor{black}{\insertsection}
                 \else
                    | \textcolor{gray}{\insertsection}
                \fi
            \fi}
            \\
            Text of second section.\\
            \vspace{2mm}

  \section{Third section} \label{sec:Third_section}
        \foreach \x in {1,...,\totvalue{section}}{
            \ifnum\x=1
                \ifnum\x=\value{section}
                    \textcolor{black}{\insertsection}
                 \else
                    \textcolor{gray}{\insertsection}
                 \fi 
            \else
                \ifnum\x=\value{section}
                    | \textcolor{black}{\insertsection}
                 \else
                    | \textcolor{gray}{\insertsection}
                \fi
            \fi}
            \\    
            Text of third section.\\
\end{frame}
\end{document}

It highlights the right position of the section, but with \insertsection I - of course - get only the current section' name.

How can I get the right section names? Can I call a section name by its number, something like \insertsection[\x] (which is not how it's working!) or can I store the section names (or their labels) in a storage array and then 'pick' out the right one with \x from the for loop?

edit:

Thx, I've come one step further after adding

\setbeamercolor{section in toc}{fg=black} (after \begin{document}) and replacing \insertsection with \tableofcontents[sections={\x}] (for black) and \tableofcontents[sections={\x}, sectionstyle=shaded] for gray.

Is there a way to prevent the linebreak after the \tableofcontents entry?

2 Answers2

1

enter image description here

Beamer provides already a sophisticated navigation (with links and everything), which you could use:

\documentclass{beamer}

\setbeamertemplate{headline}{%
  \begin{beamercolorbox}[colsep=1.5pt]{upper separation line head}
  \end{beamercolorbox}
  \begin{beamercolorbox}{section in head/foot}
    \vskip2pt\insertnavigation{\paperwidth}\vskip2pt
  \end{beamercolorbox}%
  \begin{beamercolorbox}[colsep=1.5pt]{lower separation line head}
  \end{beamercolorbox}
}

\begin{document}

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

\section{testt}
\begin{frame}
    abc
\end{frame} 

\section{testtt}
\begin{frame}
    abc
\end{frame} 

\end{document}

enter image description here

0

Thank you all,

@Skillmon: Your answer is totally suitable (see edit-part in my question), it's just that I really need it to be a line.

@samcarter: Yes, what I'm looking for in the end is a navigation bar. Unfortunately I can't use an in-build one as in \useoutertheme[subsection=false]{miniframes} because I have to use my own theme. (I can't load 2 outerthemes, can I? It just doesn't seem right.)

So, in the end the link to tex.stackexchange.com/a/303968/36296 and using \nameref did the job. The final code is this:

\documentclass{beamer}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{totcount}       
\regtotcounter{section}             % total amount of sections

\begin{document}
\setbeamercolor{section in toc}{fg=black}
\begin{frame}
  \section{First section} \label{sec:\thesection}
    \foreach \x in {1,...,\totvalue{section}}{%
            \ifnum\x=1%
                \ifnum\x=\value{section}%
                    \textcolor{black}{\nameref{sec:\x} }%
                 \else
                    \textcolor{gray}{\nameref{sec:\x} }%
                 \fi 
            \else
                \ifnum\x=\value{section}%
                    | \textcolor{black}{\nameref{sec:\x} }%
                 \else
                    | \textcolor{gray}{\nameref{sec:\x} }%
                \fi
            \fi}
            \\
            Text of first section.\\
            \vspace{2mm}

  \section{Second section} \label{sec:\thesection}
    \foreach \x in {1,...,\totvalue{section}}{%
            \ifnum\x=1%
                \ifnum\x=\value{section}%
                    \textcolor{black}{\nameref{sec:\x} }%
                 \else
                    \textcolor{gray}{\nameref{sec:\x} }%
                 \fi 
            \else
                \ifnum\x=\value{section}%
                    | \textcolor{black}{\nameref{sec:\x} }%
                 \else
                    | \textcolor{gray}{\nameref{sec:\x} }%
                \fi
            \fi}
            \\
            Text of second section.\\
            \vspace{2mm}

  \section{Third section} \label{sec:\thesection}
        \foreach \x in {1,...,\totvalue{section}}{%
            \ifnum\x=1%
                \ifnum\x=\value{section}%
                    \textcolor{black}{\nameref{sec:\x} }%
                 \else
                    \textcolor{gray}{\nameref{sec:\x} }%
                 \fi 
            \else
                \ifnum\x=\value{section}%
                    | \textcolor{black}{\nameref{sec:\x} }%
                 \else
                    | \textcolor{gray}{\nameref{sec:\x} }%
                \fi
            \fi}
            \\
            Text of third section.
\end{frame}
\end{document}

For everyone, who would like to use it as a navigationbar as well, this is how I implemented it in my outertheme.sty file:

\begin{beamercolorbox}[wd=\paperwidth, ht=\1cm];
    \begin{tikzpicture}
        \useasboundingbox[](0,0) rectangle(\the\paperwidth,1.0);            
        {\node[anchor=west, gray, font=\tiny] at (1.0, 0.70){%
           \foreach \x in {1,...,\totvalue{section}}{%
              \ifnum\x=1%
                 \ifnum\x=\value{section}%
                    \textcolor{black}{\nameref{sec:\x} }%
                 \else
                    \textcolor{gray}{\nameref{sec:\x} }%
                 \fi 
              \else
                 \ifnum\x=\value{section}%
                    | \textcolor{black}{\nameref{sec:\x} }%
                 \else
                    | \textcolor{gray}{\nameref{sec:\x} }%
                 \fi
              \fi}
        };}         
    \end{tikzpicture}
\end{beamercolorbox}

I still would like to be able to call the sections by number (usage of \nameref{sec:\x} here depends on the labels being numbered) OR create a storage-array in which the sectionnames/labels are stored. So, if anyone still has an idea on that, it's still appreciated :)