5

I'm trying to change the colors of the table of contents in a Beamer presentation, like Changing color and bullets in Beamer's table of contents except that I would like to make the "bullet" for each section a different color. Perhaps this requires reimplementing the \tableofcontents macro, which I'm willing to do, but does anyone know an easier way? (Is there a package?) I'm interested in the Warsaw theme at the moment, but input on any theme will be appreciated.

7

You will have to redefine the \sectionintoc command (original definition found in beamerbasetoc.sty) and, depending on the options used, some other template(s); in the example below I redefined the section in toc template for the default circle option (original definition found in beamerbaseauxtemplates.sty); the template is in charge of the special decorations used (the circles in the example) but the command really controls how information will go in the ToC. The color schema could be selected using an \ifcase conditional depending on the section counter. In the example code below I marked the lines used for the redefinitions using %NEW:

\documentclass{beamer}
\usetheme{Warsaw}

\makeatletter
\newcommand\SectionColor{black}%NEW
\setbeamertemplate{section in toc}
{\leavevmode\leftskip=2ex%
  \llap{%
    \usebeamerfont*{section number projected}%
   \usebeamercolor{section number projected}%
    \begin{pgfpicture}{-1ex}{0ex}{1ex}{2ex}
      \color{\SectionColor}%NEW
      \pgfpathcircle{\pgfpoint{0pt}{.75ex}}{1.3ex}
      \pgfusepath{fill}
      \pgftext[base]{\color{fg}\inserttocsectionnumber}
    \end{pgfpicture}\kern1.25ex%
  }%
  \inserttocsection\par}

\def\sectionintoc{}
\def\beamer@sectionintoc#1#2#3#4#5{%
  \ifnum\c@tocdepth>0%
  \ifnum#4=\beamer@showpartnumber%
  {
  \beamer@saveanother%
  \gdef\beamer@todo{}%
  \beamer@slideinframe=#1\relax%
  \expandafter\only\beamer@tocsections{\gdef\beamer@todo{%
      \beamer@tempcount=#5\relax%
     \renewcommand\SectionColor{%NEW 
          \ifcase\the\beamer@tempcount\or green!30!black\or yellow!60!black\or blue!20!black\or orange!30!black\else magenta!30!black\fi } %NEW
       \advance\beamer@tempcount by\beamer@sectionadjust%
      \edef\inserttocsectionnumber{\the\beamer@tempcount}%
      \def\inserttocsection{\hyperlink{Navigation#3}{#2}}%
      \beamer@tocifnothide{\ifnum\c@section=#1\beamer@toc@cs\else\beamer@toc@os\fi}%
      {
        \ifbeamer@pausesections\pause\fi%
        \ifx\beamer@toc@ooss\beamer@hidetext
          \vskip1.5em
        \else
          \vfill
        \fi
        {%
          \hbox{\vbox{%
              \def\beamer@breakhere{\\}%
              \beamer@tocact{\ifnum\c@section=#1\beamer@toc@cs\else\beamer@toc@os\fi}{section in toc}}}%
         \par%
        }%
      }%
    }
  }%
  \beamer@restoreanother%
  }
  \beamer@todo%
  \fi\fi%
}

\makeatother

\begin{document}

\begin{frame}
\tableofcontents
\end{frame}

\section{One}
\begin{frame}test\end{frame}
\section{Two}
\begin{frame}test\end{frame}
\section{Three}
\begin{frame}test\end{frame}
\section{Four}
\begin{frame}test\end{frame}
\section{Five}
\begin{frame}test\end{frame}

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