如何将部分导航栏与标题居中对齐

如何将部分导航栏与标题居中对齐

我的标题中有一个部分导航栏,我希望它显示部分居中对齐。虽然部分导航栏是右对齐的,但我尝试使用以下代码手动设置位置,将其置于中心:

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

根据上述标题的定义,以下是其中一个框架的截图: 样本框架

如何使部分导航栏中的文本(部分)居中对齐?

答案1

\hfill我在周围添加了两个\usebeamertemplate{section in head/foot},使它们位于中心。

\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}

在此处输入图片描述

相关内容