编辑

编辑

我目前正在制作一个自定义的 Beamer 主题,我非常喜欢这个smoothbars主题。但是,我想做的改变是,我希望将栏本身分成几个水平隔间,每个部分一个,每个部分都有从循环中选择的不同颜色,而不是整个栏都是单色的。

因为我认为这需要我研究smoothbars主题的实际代码,所以这就是我所做的。

我开始查看代码,并找到以下行

\insertnavigation{\paperwidth}

它扩展为具有大量跳过和装箱命令的表达式,但还包含

\dohead 

然后展开为一个循环

\beamer@headcounter =0\relax 
\loop 
\ifnum \beamer@headcounter <\beamer@totalheads \advance\beamer@headcounter by1\relax
\csname @@head\the \beamer@headcounter \endcsname
\repeat

我天真地以为这个循环会遍历各个部分,并在某些框环境中打印部分标题,所以我查看了的内容\csname @@head\the \beamer@headcounter \endcsname。有趣的是,这些内容精确地扩展到文件行的内容*.nav,例如

\sectionentry {1}{Introduction}{2}{Introduction}{0}

这是有道理的,因为该.nav文件包含了所有必要的信息 - 但我感到困惑的是,不仅出现了章节标题,还出现了各种其他内容,比如

\beamer@framepages {1}{1}

或者

\beamer@sectionpages {1}{1}
\beamer@subsectionpages {1}{1}

smoothbar我真的不明白这里发生了什么。为了以5 种不同颜色为周期改变每个部分的背景颜色,最合理的干预部分是什么?

编辑

根据要求,这里是 MWE。它并不是真正的 MWE,因为它会产生问题,因为我不太了解发生了什么,无法认真尝试正确着色。但是,我不明白为什么取消注释命令会导致布局\colorbox完全中断,所以这可能是一个不错的起点。

\documentclass{beamer}
\usecolortheme{orchid}
\usecolortheme{whale}

\makeatletter
% this code is the result of me collecting the bits & pieces
% from the macro definitions in `beamerouterthemesmoothbars.sty`
\defbeamertemplate*{headline}{smoothbars theme}{%
    \vbox {%
      \beamer@xpos =0\relax \beamer@ypos=1\relax
      \hbox to \paperwidth{
        % this is some spacing that I don't really understand what it does
        \hskip .3cm\setbox\beamer@sectionbox =\hbox {\kern 1sp}
        \hskip -1.875ex plus-1fill
        \global \beamer@section@min@dim \z@
        % loop over the entries of the *.nav file
        \beamer@headcounter =0\relax
        \loop
        \ifnum \beamer@headcounter <\beamer@totalheads\advance \beamer@headcounter by1\relax
        % I would have expected that putting a 'colorbox' here would do the trick of coloring the individual section headings
        % however, very strange things happen when uncommenting the following line, which probably has to do with the fact
        % that the loop runs over 17 entries (instead of just 2, as I would have expected)
        %\colorbox{red}{ 
          \csname @@head\the \beamer@headcounter \endcsname
        %}
        \repeat
        % some more spacing commands
        \beamer@section@set@min@width \box \beamer@sectionbox
        \hfil \hskip .3cm
      }
    }
}%
\makeatother

% now comes some dummy code just to have some slides to look at
\title{Hello World}

\begin{document}

\maketitle

\section{Introduction}

\begin{frame}{Hello!}
  \begin{itemize}
    \item Hello!
  \end{itemize}
\end{frame}

\section{Further stuff}

\begin{frame}{Hello!}
  \begin{itemize}
    \item Hello!
  \end{itemize}
\end{frame}

\end{document}

答案1

我怎么没colorseries早点发现呢?它们真的很方便!

以下假设各部分的长度相似:

\documentclass{beamer}
\usecolortheme{orchid}
\usecolortheme{whale}
\useoutertheme{smoothbars}

\setbeamerfont{section in head/foot}{series=\bfseries}
\setbeamercolor{section in head/foot}{fg=black, bg=}

\usepackage{tikz}

\definecolorseries{foo}{rgb}{last}{red}{blue}
\resetcolorseries[3]{foo}

\makeatletter
\setbeamertemplate{headline}{%
    \foreach \i in {1,...,\number\totvalue{totalsection}}{%
            {\color{foo!![\i]}\rule{\dimexpr\paperwidth/\number\totvalue{totalsection}\relax}{7ex}}%
    }
  \vskip-7ex%
  \begin{beamercolorbox}[ignorebg,ht=2.25ex,dp=3.75ex]{section in head/foot}
    \insertnavigation{\paperwidth}
  \end{beamercolorbox}%
}%
\makeatother


\usepackage{totcount}

\newcounter{totalsection}
\regtotcounter{totalsection}

\AtBeginDocument{%
    \pretocmd{\section}{\refstepcounter{totalsection}}{\typeout{Yes, prepending was successful}}{\typeout{No, prepending was not it was successful}}%
}%

\title{Hello World}

\begin{document}

\maketitle

\section{Introduction}

\begin{frame}{Hello!}
  \begin{itemize}
    \item Hello!
  \end{itemize}
\end{frame}

\section{Further stuff}

\begin{frame}{Hello!}
  \begin{itemize}
    \item Hello!
  \end{itemize}
\end{frame}

\section{some stuff}

\begin{frame}{Hello!}
  \begin{itemize}
    \item Hello!
  \end{itemize}
\end{frame}


\end{document}

在此处输入图片描述

相关内容