4

I have a section navigation bar in my headline, and I want it to show the sections center aligned. Although, the section navigation bar is right aligned, I tried to position it in the center by setting the position manually using the following code:

\setbeamertemplate{headline}{%
\leavevmode%
  \hbox{%
    \begin{beamercolorbox}[wd=\paperwidth,ht=12.5ex]{section in head/foot}%
      \insertsectionnavigation{0.5\paperwidth}
    \end{beamercolorbox}%
  }
}

With the above definition of the headline, here is the snap of one of the frames: sample frame

How can I get the text (the sections) in the section navigation bar center aligned?

  • Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – ebosi Jun 2 '16 at 8:31
  • Can you please post a complete minimal working example instead of a code fragment? – user36296 Jun 2 '16 at 9:19
  • please see the edits @samcarter – user107054 Jun 3 '16 at 7:39
3

I added two \hfill around \usebeamertemplate{section in head/foot} to make them centred.

\documentclass{beamer}

\usetheme{Berlin}

\setbeamertemplate{headline}{%
    \leavevmode%
    \hbox{%
        \begin{beamercolorbox}[wd=\paperwidth,ht=12.5ex]{section in head/foot}%
            \insertsectionnavigation{\paperwidth}
        \end{beamercolorbox}%
    }
}

\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%
                                {\hfill\usebeamertemplate{section in head/foot}\hfill}%
                                \else%
                                {\hfill\usebeamertemplate{section in head/foot shaded}\hfill}%
                                \fi\hskip0.3cm}}}%
                    \ht\beamer@tempbox=1.6875ex\dp\beamer@tempbox=0.75ex%
                    \box\beamer@tempbox\fi}%
                \dohead\vskip0.5625ex}}\hfil}}
\makeatother


\begin{document}

\section{loooooooooooooong}
\frame{as}

\section{er}
\frame{sd}

\end{document}

enter image description here

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.