如何在示例程序中格式化示例块,如定理块?

问题描述 投票:0回答:1

我想像定理块那样制作与定理块相同格式的示例块(除了我希望块标题背景颜色为青色)。我怎样才能做到这一点?我试图复制粘贴适用于定理的代码,并将“ theorem”替换为“ example”,但没有成功。 (我使用\ usetheme {Aalborg})。

\uselanguage{danish}
\languagepath{danish}
\deftranslation[to=danish]{Example}{Eksempel}
\makeatletter
\setbeamertemplate{example begin}{%
  \setbeamercolor{block title}{bg=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}%
  \begin{\insertexampleblockenv}
    {%
      \insertexamplename
      \insertexamplenumber
      \ifx\insertexampleaddition\@empty\else\    \insertexampleaddition\fi%
    }%
}

\setbeamertemplate{example end}{%
    \end{\insertexampleblockenv}%
}

\makeatother
latex beamer
1个回答
0
投票

[example]会自动继承theorem的格式,因此您只需要调整颜色:

\documentclass{beamer}

\usetheme{Aalborg}

\uselanguage{danish}
\languagepath{danish}
\deftranslation[to=danish]{Example}{XYZ}

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


\makeatletter
\setbeamercolor{block title example}{bg=orange,fg=black}
\addtobeamertemplate{block example begin}{}{
  \setbeamercolor{itemize item}{fg=orange!100!white}%
  \setbeamercolor{itemize item}{fg=orange!100!white}%
  \setbeamercolor{itemize subitem}{fg=orange!100!white}%
  \setbeamercolor{itemize subsubitem}{fg=orange!100!white}%
  \setbeamercolor{enumerate item}{fg=orange!100!black}%
  \setbeamercolor{enumerate subitem}{fg=orange!100!black}%
  \setbeamercolor{enumerate subsubitem}{fg=orange!100!black}%  
}

\setbeamertemplate{theorem begin}{%
  \setbeamercolor{block title}{bg=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}%
  \begin{\inserttheoremblockenv}
    {%
      \inserttheoremname
      \inserttheoremnumber
      \ifx\inserttheoremaddition\@empty\else\ \inserttheoremaddition\fi%
    }%
    \normalfont%
}

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

\makeatother

\begin{document}

\begin{frame}

\begin{theorem}[test]
content...
\begin{itemize}
\item test
\end{itemize}
\end{theorem}

\begin{example}[test]
content...
\begin{itemize}
\item test
\end{itemize}
\end{example}


\end{frame} 

\end{document}

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.