How to change the color of bullet-points in default environments in beamer?

血红的双手。 提交于 2019-12-18 09:46:29

问题


I am making a beamer presentation using

\usetheme{Aalborg}

and I want to create blocks for definitions, theorems, remarks, exercises, proofs, examples etc. It seems that the default example-environment inherits some features from the default theorem-environment.

I want to be able to make itemizations and enumerations within the example-block environment such that the bullet-points have the same color as the background color of the example-block header. Right now, the color of the bullet-points in the example-environment have the same color as the background color of the theorem-environment block heder. How can this be fixed?

\documentclass[mathserif,9pt,trans]{beamer}
\usetheme[shownavsym,right]{Aalborg}

\setbeamertemplate{navigation symbols}{\insertframenavigationsymbol      \insertsectionnavigationsymbol \insertbackfindforwardnavigationsymbol}  

\setbeamertemplate{section in toc}{\inserttocsection} % Redundant in relation to generation of ToC with enumerated (sub)sections???
\setbeamertemplate{section in toc}[sections numbered] % Automatic enumeration of sections


\setbeamertemplate{subsection in toc}{\leavevmode\leftskip=3.14em    \rlap{\hskip-2em\inserttocsectionnumber.\inserttocsubsectionnumber}\inserttocsubsection\par} 

\setbeamertemplate{subsubsection in toc}{\leavevmode\leftskip=6.9em \rlap{\hskip-3em\inserttocsectionnumber.\inserttocsubsectionnumber.\inserttocsubsubsectionnumber}\inserttocsubsubsection\par} 

\definecolor{UniBlue}{RGB}{33,26,82}
\definecolor{UniGray}{RGB}{84,97,110}
\definecolor{dgreen}{rgb}{0.,0.6,0.} 


\setbeamercolor{frametitle}{fg=UniGray} % Color of text in frametitles


\setbeamercolor{normal text}{fg=UniGray} % Change the normal text color background:


\newcommand{\chref}[2]{%
  \href{#1}{{\usebeamercolor[bg]{Aalborg}#2}}
}% colored hyperlinks


\usepackage{pgfpages}



\usepackage{fixltx2e}
\usepackage{etex}

\usepackage[utf8]{inputenc}
\usepackage{ae,aecompl}
\usepackage[english,danish]{babel}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{mathrsfs}

\usepackage{lipsum} 

\usepackage{xcolor}
\definecolor{aaublue}{RGB}{33,26,82}% dark blue
\usepackage{graphicx}
\usepackage{caption}
\usepackage{array,booktabs}
\usepackage{framed}
\usepackage{ulem}
\usepackage{etoolbox} % In order to make bullet-points in the same color as the block header.
\usepackage[makeroom]{cancel} 
\usepackage{pifont}
\usepackage{extarrows}
\usepackage{mathtools}
\usepackage{picins}
\usepackage{centernot} 

\makeatletter
\newcommand{\xMapsto}[2][]{\ext@arrow 0599{\Mapstofill@}{#1}{#2}}
\def\Mapstofill@{\arrowfill@{\Mapstochar\Relbar}\Relbar\Rightarrow}
\makeatother

\usepackage{wrapfig} 

\usepackage{pgfplots}
\pgfplotsset{%
       compat=1.8
     }

\setbeamercolor*{normal text}{fg=UniGray,bg=blue!0!white}                             

\mode<presentation>

\setbeamercolor*{example text}{fg=green!0!white}

\setbeamercolor*{structure}{fg=aaublue} % Color of titlepage headline etc.
\setbeamercolor*{structure2}{fg=blue!0!white}
\setbeamercolor*{structure3}{fg=blue!100!white}

\setbeamercolor{palette primary}{use={structure,normal text},fg=structure.fg,bg=normal text.bg!75!black}
\setbeamercolor{palette primary2}{use={structure3,normal text},fg=structure3.fg,bg=normal text.bg!100!white}
\setbeamercolor{palette secondary}{use={structure,normal text},fg=structure.fg,bg=normal text.bg!60!black}
\setbeamercolor{palette secondary2}{use={structure3,normal text},fg=structure3.fg,bg=normal text.bg!90!black}
\setbeamercolor{palette tertiary}{use={structure,normal text},fg=structure.fg,bg=normal text.bg!45!black}
\setbeamercolor{palette quaternary}{use={structure,normal text},fg=structure.fg,bg=normal text.bg!30!black}

\newenvironment<>{defi}[1]{
    \setbeamercolor{block title}{fg=white,bg=blue!100!black}
    \setbeamertemplate{itemize items}[circle]                    % Shape of bullet-points
    \begin{block}#2{#1}}{\end{block}}
\AtBeginEnvironment{defi}{\setbeamercolor{itemize item}{fg=blue!100!black}}         % Color of bullet-points (itemize) = Color of header (requires \usepackage{etoolbox})
\AtBeginEnvironment{defi}{\setbeamercolor{itemize subitem}{fg=blue!100!black}}      % Color of bullet-points (itemize) = Color of header (requires \usepackage{etoolbox})
\AtBeginEnvironment{defi}{\setbeamercolor{itemize subsubitem}{fg=blue!100!black}}   % Color of bullet-points (itemize) = Color of header (requires \usepackage{etoolbox})
\AtBeginEnvironment{defi}{\setbeamercolor{enumerate item}{fg=blue!100!black}}       % Color of bullet-points (enumerate) = Color of header (requires \usepackage{etoolbox})
\AtBeginEnvironment{defi}{\setbeamercolor{enumerate subitem}{fg=blue!100!black}}    % Color of bullet-points (enumerate) = Color of header (requires \usepackage{etoolbox})
\AtBeginEnvironment{defi}{\setbeamercolor{enumerate subsubitem}{fg=blue!100!black}} % Color of bullet-points (enumerate) = Color of header (requires \usepackage{etoolbox})

\uselanguage{danish}
\languagepath{danish}
\deftranslation[to=danish]{Example}{Eksempel}
\deftranslation[to=danish]{Theorem}{Sætning}

\usepackage{etoolbox}
\undef{\example}
\theoremstyle{example}
\newtheorem{example}{\translate{Example}}


\makeatletter
\setbeamercolor{block title example}{bg=cyan,fg=white}
\addtobeamertemplate{block example begin}{}{
  \setbeamertemplate{itemize items}[circle]                    % Shape of bullet-points
  \setbeamercolor{itemize item}{fg=cyan!100!white}%
  \setbeamercolor{itemize item}{fg=cyan!100!white}%
  \setbeamercolor{itemize subitem}{fg=cyan!100!white}%
  \setbeamercolor{itemize subsubitem}{fg=cyan!100!white}%
  \setbeamercolor{enumerate item}{fg=cyan!100!black}%
  \setbeamercolor{enumerate subitem}{fg=cyan!100!black}%
  \setbeamercolor{enumerate subsubitem}{fg=cyan!100!black}%
}

\setbeamertemplate{theorem begin}{%
  \setbeamertemplate{itemize items}[circle]                    % Shape of bullet-points
  \setbeamercolor{block title}{bg=dgreen!100!white}%
  \setbeamercolor{itemize item}{fg=dgreen!100!white}%
  \setbeamercolor{itemize subitem}{fg=dgreen!100!white}%
  \setbeamercolor{itemize subsubitem}{fg=dgreen!100!white}%
  \setbeamercolor{enumerate item}{fg=dgreen!100!black}%
  \setbeamercolor{enumerate subitem}{fg=dgreen!100!black}%
  \setbeamercolor{enumerate subsubitem}{fg=dgreen!100!black}%
  \begin{\inserttheoremblockenv}
    {%
      \inserttheoremname
      \inserttheoremnumber
      \ifx\inserttheoremaddition\@empty\else\ \inserttheoremaddition\fi%
    }%
    \normalfont%
}

\setbeamertemplate{theorem end}{%
    \end{\inserttheoremblockenv}%
}

\makeatother

\def \roed {normal text.bg!10!red}
\newcounter{opgave}[part] % Enumeration of problems/exercises. Reset at beginning of every new "part"
\renewcommand{\theopgave}{\arabic{opgave}}
\resetcounteronoverlays{opgave}  % Exercise # in the header should not increment when uncovering
\newenvironment<>{opgave}[1]{
    \setbeamercolor{block title}{fg=white,bg=\roed}
    \begin{block}#2{\refstepcounter{opgave}Exercise \theopgave #1}}{\end{block}}
\AtBeginEnvironment{opgave}{\setbeamercolor{itemize item}{fg=\roed}}         % Color of bullet-points (itemize) = Color of header (requires     \usepackage{etoolbox})
\AtBeginEnvironment{opgave}{\setbeamercolor{itemize subitem}{fg=\roed}}      % Color of bullet-points (itemize) = Color of header (requires                     \usepackage{etoolbox})
\AtBeginEnvironment{opgave}{\setbeamercolor{itemize subsubitem}{fg=\roed}}   % Color of bullet-points (itemize) = Color of header (requires \usepackage{etoolbox})
\AtBeginEnvironment{opgave}{\setbeamercolor{enumerate item}{fg=\roed}}       % Color of bullet-points (enumerate) = Color of header (requires \usepackage{etoolbox})
\AtBeginEnvironment{opgave}{\setbeamercolor{enumerate subitem}{fg=\roed}}    % Color of bullet-points (enumerate) = Color of header (requires \usepackage{etoolbox})
\AtBeginEnvironment{opgave}{\setbeamercolor{enumerate subsubitem}{fg=\roed}} % Color of bullet-points (enumerate) = Color of header (requires \usepackage{etoolbox})

\newenvironment<>{sektion}[1]{
    \setbeamercolor*{block body}{bg=aaublue,fg=white}
    \setbeamertemplate{blocks}[rounded][shadow=false]
    \begin{block}#2{#1}}{\end{block}}

\setbeamercolor*{block body}{bg=black!10!white,fg=black} 
\setbeamercolor*{block body alerted}{bg=normal text.bg!90!black,fg=black} 
\setbeamercolor*{block body example}{bg=normal text.bg!90!black,fg=black} 
\setbeamercolor*{block title}{parent=structure2,bg=normal text.bg!0!blue}
\setbeamercolor*{block title alerted}{use={normal text,alerted text},fg=alerted text.fg!0!white,bg=normal text.bg!10!red}
\setbeamercolor*{block title example}{use={normal text,example text},fg=white,bg=cyan}
\setbeamercolor*{block title theorem}{use={normal text,example text},fg=example text.fg!100!normal text.fg,bg=normal text.bg!0!dgreen}


\setbeamercolor{item projected}{fg=black}

\setbeamercolor*{sidebar}{parent=palette primary2} 

\setbeamercolor{palette sidebar primary}{use=structure3,fg=structure3.fg}

\setbeamercolor{palette sidebar secondary}{use=structure3,fg=structure3.fg}

\setbeamercolor{palette sidebar tertiary}{use=structure3,fg=structure3.fg}

\setbeamercolor{palette sidebar quaternary}{use=structure3,fg=structure3.fg}

\setbeamercolor*{separation line}{}
\setbeamercolor*{fine separation line}{}

\setbeamertemplate{blocks}[rounded][shadow=true] 

\pgfdeclareverticalshading[lower.bg,upper.bg]{bmb@transition}{200cm}{color(0pt)=(lower.bg); color(4pt)=(lower.bg); color(4pt)=(upper.bg)}

\usepackage{multirow}
\usepackage{hhline}
\usepackage{multicol}
\usepackage{colortbl}
\usepackage{rotating}
\usepackage{tabularx}
\usepackage{cellspace}

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

\usepackage{epstopdf}
\usepackage{calc}
\usepackage{tikz}
\usepackage{scalefnt}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{xstring}

\usepackage[colorinlistoftodos, textwidth=\marginparwidth, textsize=scriptsize, ]{todonotes}





\usepackage[compatibility=false]{caption}
\usepackage{subcaption}
\usepackage[labelformat=empty]{caption}

\usepackage[amssymb]{SIunits}


\newcounter{opg}[section]
\newcommand{\opg}{\refstepcounter{opg} \subsection*{Opgave \theopg}}
\newcounter{spm}[opg]
\newenvironment{spm}{\begin{enumerate}[a)]\setcounter{enumi}{\thespm}}{\setcounter{spm}{\arabic{enumi}}\end{enumerate}}
\newcounter{svar}[opg]
\newenvironment{svar}{\begin{enumerate}[a)]\setcounter{enumi}{\thesvar}}{\setcounter{svar}{\arabic{enumi}}\end{enumerate}}


\begin{document}

\section{Funktioner af to variable}
\begin{frame}{}
    \begin{minipage}{0.99\textwidth}
    \begin{sektion}{}
        \begin{center}
           \Huge{Example-block\phantom{g}}
        \end{center}
    \end{sektion}
    \end{minipage}
\end{frame}
\begin{frame}[<+->]{Example-block\phantom{g}}\label{frame:example}
    \begin{minipage}{0.99\textwidth}
    \begin{example}%
        Itemize
        \begin{itemize}
            \item Item 1
                  \begin{itemize}
                      \item Subitem 1.1
                            \begin{itemize}
                                \item Subsubitem 1.1.1
                                \item Subsubitem 1.1.2
                            \end{itemize}
                      \item Subitem 1.2
                  \end{itemize}
            \item Item 2
        \end{itemize}
        Enumerate
        \begin{enumerate}
            \item Item 1
                  \begin{enumerate}
                      \item Subitem 1.1
                            \begin{enumerate}
                                \item Subsubitem 1.1.1
                                \item Subsubitem 1.1.2 
                            \end{enumerate}
                      \item Subitem 1.2
                            \begin{enumerate}
                                \item Subsubitem 1.2.1
                            \end{enumerate} 
                  \end{enumerate}
            \item Item 2
        \end{enumerate}
    \label{example:environments}
    In Eksempel \ref{example:environments}, the color of the bullet-points in both the itemize-environment and the enumerate-environment are different from the background color of the block header.
    \end{example}
    \end{minipage}
\end{frame}
\begin{frame}{}
    \begin{minipage}{0.99\textwidth}
    \begin{sektion}{}
        \begin{center}
           \Huge{Theorem-block\phantom{g}}
        \end{center}
    \end{sektion}
    \end{minipage}
\end{frame}
\section{Theorem-environment}
\begin{frame}[<+->]{Theorem-environment\phantom{g}}\label{frame:theorem}
\begin{minipage}{0.99\textwidth}
\begin{theorem}[ \href{https://mathinsight.org/directional_derivative_gradient_introduction}{\beamergotobutton{Link: Level- and contour curves}}]
    Itemize
    \begin{itemize}
        \item Item 1
              \begin{itemize}
                  \item Subitem 1.1
                        \begin{itemize}
                            \item Subsubitem 1.1.1
                            \item Subsubitem 1.1.2
                        \end{itemize}
                  \item Subitem 1.2
              \end{itemize}
        \item Item 2
    \end{itemize}
    Enumerate
    \begin{enumerate}
        \item Item 1
              \begin{enumerate}
                  \item Subitem 1.1
                        \begin{enumerate}
                            \item Subsubitem 1.1.1
                            \item Subsubitem 1.1.2 
                        \end{enumerate}
                  \item Subitem 1.2
                        \begin{enumerate}
                            \item Subsubitem 1.2.1
                        \end{enumerate} 
              \end{enumerate}
        \item Item 2
    \end{enumerate}
\label{theo:environments}
\end{theorem}
Sætning \ref{theo:environments} (theorem-environment): color of bullet-points=color of block header background.
\end{minipage}
\end{frame}
\end{document}

回答1:


If you use \setbeamertemplate{blocks}[rounded][shadow=true] after you made all the adjustments of colours etc. you simply overwrite them again with the default behaviour of blocks. So you should change the order.

Some other comments about your code:

  • You can find an explicit warning in your log file telling you not to use the mathserif document class option, but \usefonttheme[onlymath]{serif}. Don't ignore warnings!

  • first setting \setbeamertemplate{section in toc}{\inserttocsection} and then immediately overwriting it with \setbeamertemplate{section in toc}[sections numbered] makes no sense

  • with an up-to-date tex distribution the following package are no longer necessary: \usepackage{fixltx2e}, \usepackage{etex}, \usepackage[utf8]{inputenc}

  • The following package are already loaded by beamer \usepackage{xcolor}, \usepackage{graphicx}, \usepackage{etoolbox}

  • the following packages are not necessary, beamer has its own mechanism for these: \usepackage{caption}, \usepackage{multicol}

  • don't load the same package multiple times, especially not with different options. You load the caption package no less than 3 times!!!!

  • Don't use \usepackage{colortbl}, but add xcolor={table} as documentclass option


\documentclass[9pt,trans]{beamer}
\usefonttheme[onlymath]{serif}
\usetheme[shownavsym,right]{Aalborg}
\setbeamertemplate{blocks}[rounded][shadow=true] 

\definecolor{dgreen}{rgb}{0.,0.6,0.} 

\usepackage[english,danish]{babel}

\definecolor{aaublue}{RGB}{33,26,82}% dark blue
\usepackage{etoolbox} % In order to still use an outdated beamer  version

\mode<presentation>

\setbeamercolor*{example text}{fg=green!0!white}

\uselanguage{danish}
\languagepath{danish}
\deftranslation[to=danish]{Example}{Eksempel}
\deftranslation[to=danish]{Theorem}{Sætning}

\usepackage{etoolbox}
\undef{\example}
\theoremstyle{example}
\newtheorem{example}{\translate{Example}}

\setbeamercolor{block title example}{bg=cyan,fg=white}
\addtobeamertemplate{block example begin}{}{
  \setbeamertemplate{itemize items}[circle]                    % Shape of bullet-points
  \setbeamercolor{itemize item}{fg=cyan!100!white}%
  \setbeamercolor{itemize item}{fg=cyan!100!white}%
  \setbeamercolor{itemize subitem}{fg=cyan!100!white}%
  \setbeamercolor{itemize subsubitem}{fg=cyan!100!white}%
  \setbeamercolor{enumerate item}{fg=cyan!100!black}%
  \setbeamercolor{enumerate subitem}{fg=cyan!100!black}%
  \setbeamercolor{enumerate subsubitem}{fg=cyan!100!black}%
}

\setbeamertemplate{theorem begin}{%
  \setbeamertemplate{itemize items}[circle]                    % Shape of bullet-points
  \setbeamercolor{block title}{bg=dgreen!100!white}%
  \setbeamercolor{itemize item}{fg=dgreen!100!white}%
  \setbeamercolor{itemize subitem}{fg=dgreen!100!white}%
  \setbeamercolor{itemize subsubitem}{fg=dgreen!100!white}%
  \setbeamercolor{enumerate item}{fg=dgreen!100!black}%
  \setbeamercolor{enumerate subitem}{fg=dgreen!100!black}%
  \setbeamercolor{enumerate subsubitem}{fg=dgreen!100!black}%
  \begin{\inserttheoremblockenv}
    {%
      \inserttheoremname
      \inserttheoremnumber
      \ifx\inserttheoremaddition\@empty\else\ \inserttheoremaddition\fi%
    }%
    \normalfont%
}

\setbeamertemplate{theorem end}{%
    \end{\inserttheoremblockenv}%
}


\setbeamercolor*{block body}{bg=black!10!white,fg=black} 
\setbeamercolor*{block body alerted}{bg=normal text.bg!90!black,fg=black} 
\setbeamercolor*{block body example}{bg=normal text.bg!90!black,fg=black} 
\setbeamercolor*{block title}{parent=structure2,bg=normal text.bg!0!blue}
\setbeamercolor*{block title alerted}{use={normal text,alerted text},fg=alerted text.fg!0!white,bg=normal text.bg!10!red}
\setbeamercolor*{block title example}{use={normal text,example text},fg=white,bg=cyan}
\setbeamercolor*{block title theorem}{use={normal text,example text},fg=example text.fg!100!normal text.fg,bg=normal text.bg!0!dgreen}

\makeatletter
\pgfdeclareverticalshading[lower.bg,upper.bg]{bmb@transition}{200cm}{color(0pt)=(lower.bg); color(4pt)=(lower.bg); color(4pt)=(upper.bg)}
\makeatother

\begin{document}

\begin{frame}
    \begin{example}%
    \begin{itemize}
        \item Item 1
    \end{itemize}
    \begin{enumerate}
        \item Item 1
    \end{enumerate}
    \end{example}

        \begin{theorem}
    \begin{itemize}
        \item Item 1
    \end{itemize}
    \begin{enumerate}
        \item Item 1
    \end{enumerate}
\end{theorem}
\end{frame}
\end{document}



来源:https://stackoverflow.com/questions/58477954/how-to-change-the-color-of-bullet-points-in-default-environments-in-beamer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!