仅更改目录中当前部分的项目符号颜色

仅更改目录中当前部分的项目符号颜色

在我的目录中,我想使用不同的颜色突出显示当前部分。回答以下问题这个问题,我已设法使用更改当前部分的文本颜色

\setbeamercolor{section in toc}{fg=alerted text.fg, fg = red}

现在我还想更改当前部分的项目符号颜色,但到目前为止,我只成功更改了目录中所有项目符号的颜色。如何更改目录中当前部分项目符号的颜色?

以下是 MWE:

\documentclass[xcolor=dvipsnames]{beamer}
\usecolortheme{dolphin} 
\useinnertheme{rectangles} % adds squared bullets to TOC

% Define colors of our university
\definecolor{UniGreen}{RGB}{ 0,139,0}
\definecolor{TitleGreen}{RGB}{0,120,0}
\setbeamercolor{title}{fg=TitleGreen}
\setbeamercolor{structure}{fg=UniGreen} 
\setbeamercolor{item projected}{bg=UniGreen, fg=white} %define color of the item-bullets
\setbeamercolor{button}{bg=UniGreen}


\AtBeginSection[]
{
\setbeamercolor{section in toc}{fg=alerted text.fg, fg = red} % this changes name of current section to red as desired
\setbeamercolor{section in toc shaded}{bg=structure!20, fg=structure}
\setbeamertemplate{section in toc shaded}[default][100]
\setbeamercolor{section number projected}{fg=alerted, bg=red,fg=white} % THIS LINE OF CODE CHANGES ALL THE BULLETS IN THE TOC TO RED
}

\begin{document}
\section{Test section one}
\begin{frame} test \end{frame}
\section{Test section two}
\begin{frame} test \end{frame}

\frame{\frametitle{Outline}\tableofcontents[currentsection, currentsubsection, subsectionstyle = show, subsubsectionstyle=show]
} 

\section{Test section three}
\begin{frame} test \end{frame}
\section{Test section four}
\begin{frame} test \end{frame}

\end{document}

答案1

从我发现的情况来看,仅通过重新定义颜色似乎无法实现您想要的行为。因此,我的建议是重新定义模板section in toc。为此,请查看您的内部主题,它rectangles本身只会加载\setbeamertemplate{sections/subsections in toc}[square],因此请查看beamerbaseauxtemplates.sty原始定义,然后将其用作我们模板的基础square_special,如下所示:

\defbeamertemplate*{section in toc}{square_special}
{\leavevmode\leftskip=1.75ex%
    \llap{%
        \usebeamerfont*{section number projected}%
        %\usebeamercolor[bg]{section number projected}%
        \vrule width2.25ex height1.85ex depth.4ex%
        \hskip-2.25ex%
        \hbox to2.25ex{\hfil\usebeamercolor[fg]{section number projected}\inserttocsectionnumber\hfil}}%
    \kern1.25ex\inserttocsection\par}

我在这里做了什么?好吧,我删除了投影的部分编号的背景颜色的原始选择,而只是使用已安装的颜色(部分标题的颜色)。但是我们仍然需要fg的颜色section number projected

它在您的 MWE 中看起来如下:

\documentclass[xcolor=dvipsnames]{beamer}
\usecolortheme{dolphin} 
\useinnertheme{rectangles} % adds squared bullets to TOC

% Define colors of our university
\definecolor{UniGreen}{RGB}{ 0,139,0}
\definecolor{TitleGreen}{RGB}{0,120,0}
\setbeamercolor{title}{fg=TitleGreen}
\setbeamercolor{structure}{fg=UniGreen} 
\setbeamercolor{item projected}{bg=UniGreen, fg=white} %define color of the item-bullets
\setbeamercolor{button}{bg=UniGreen}


\AtBeginSection[]
{
    \setbeamercolor{section in toc}{fg=alerted text.fg, fg = red} % this changes name of current section to red as desired
    \setbeamercolor{section in toc shaded}{bg=structure!20, fg=structure}
    \setbeamertemplate{section in toc shaded}[default][100]
    \setbeamercolor{section number projected}{fg=alerted, bg=red,fg=white} % THIS LINE OF CODE CHANGES ALL THE BULLETS IN THE TOC TO RED
}

\defbeamertemplate*{section in toc}{square_special}
{\leavevmode\leftskip=1.75ex%
    \llap{%
        \usebeamerfont*{section number projected}%
        %\usebeamercolor[bg]{section number projected}%
        \vrule width2.25ex height1.85ex depth.4ex%
        \hskip-2.25ex%
        \hbox to2.25ex{\hfil\usebeamercolor[fg]{section number projected}\inserttocsectionnumber\hfil}}%
    \kern1.25ex\inserttocsection\par}

\begin{document}
    \section{Test section one}
    \begin{frame} test \end{frame}
\section{Test section two}
\begin{frame} test \end{frame}

\frame{\frametitle{Outline}\tableofcontents[currentsection, currentsubsection, subsectionstyle = show, subsubsectionstyle=show]
} 

\section{Test section three}
\begin{frame} test \end{frame}
\section{Test section four}
\begin{frame} test \end{frame}

\end{document}

总体而言,我建议进行一些简化,但我想这些简化对于您的主题来说是必要的。这是我的解决方案中的大纲:

在此处输入图片描述

相关内容