定理后不换行,保留 Beamer 警报颜色

定理后不换行,保留 Beamer 警报颜色

这个答案展示了如何修改定理环境以避免在定理标题后出现换行符(当垂直空间是一种宝贵的商品时,这很有用)。

我想修改该答案,以便定理标题的文本(我的意思是文本“定理 1.1 (ABC)”)尊重警报。以下是基于该主题中的答案的示例:

\documentclass[envcountsect]{beamer}

\usetheme{CambridgeUS}
\usefonttheme{serif}

\usepackage{etoolbox}

\makeatletter
\setbeamertemplate{theorem begin}
{%
\begin{\inserttheoremblockenv}
  {}{\usebeamerfont*{block title}\usebeamercolor[fg]{block title}%
  \inserttheoremname
  \inserttheoremnumber
  \ifx \inserttheoremaddition \empty \else\ (\inserttheoremaddition)\fi
  \inserttheorempunctuation}
  \normalfont
  }
  \setbeamertemplate{theorem end}{\end{\inserttheoremblockenv}}
\makeatother

\begin{document}

\section{ABC}

\begin{frame}

\begin{alertenv}<+>
  \begin{theorem}[ABC]
    This is a theorem
  \end{theorem}
\end{alertenv}

  \begin{theorem}[DEF]
    This is a another theorem (not alerted).
  \end{theorem}

  Text.

  \begin{block}{Block title}
    A block with title.
  \end{block}

  Text.

  \begin{block}{}
    A block without title.
  \end{block}

\end{frame}

\end{document}

请注意使用颜色“块标题”的代码。因此,在警报模式下,它仍然使用“块标题”。当文本需要警报时,如何使用“块标题警报”?也就是说,在示例文件中,我希望“定理 1.1 (ABC)”采用警报颜色,而“定理 1.2 (DEF)”采用非警报颜色。

答案1

如果您使用定理标题的默认蓝色,则可以用- 一种会被警报环境改变的颜色替换该block title颜色:local structure

\documentclass[envcountsect]{beamer}

\usetheme{CambridgeUS}
\usefonttheme{serif}

\usepackage{etoolbox}

\makeatletter
\setbeamertemplate{theorem begin}
{%
\begin{\inserttheoremblockenv}
  {}{\usebeamerfont*{block title}\usebeamercolor[fg]{local structure}%
  \inserttheoremname
  \inserttheoremnumber
  \ifx \inserttheoremaddition \empty \else\ (\inserttheoremaddition)\fi
  \inserttheorempunctuation}
  \normalfont
  }
  \setbeamertemplate{theorem end}{\end{\inserttheoremblockenv}}
\makeatother

\begin{document}

\section{ABC}

\begin{frame}

\begin{alertenv}<+>
  \begin{theorem}[ABC]
    This is a theorem
  \end{theorem}
\end{alertenv}

  \begin{theorem}[DEF]
    This is a another theorem (not alerted).
  \end{theorem}

  Text.

  \begin{block}{Block title}
    A block with title.
  \end{block}

  Text.

  \begin{block}{}
    A block without title.
  \end{block}

\end{frame}

\end{document}

如果您对块标题和/或结构使用特殊颜色,则可以告诉警报环境更改块标题颜色:

\documentclass[envcountsect]{beamer}

\usetheme{CambridgeUS}
\usefonttheme{serif}

\usepackage{etoolbox}

\makeatletter
\setbeamertemplate{theorem begin}
{%
\begin{\inserttheoremblockenv}
  {}{\usebeamerfont*{block title}\usebeamercolor[fg]{block title}%
  \inserttheoremname
  \inserttheoremnumber
  \ifx \inserttheoremaddition \empty \else\ (\inserttheoremaddition)\fi
  \inserttheorempunctuation}
  \normalfont
  }
  \setbeamertemplate{theorem end}{\end{\inserttheoremblockenv}}
  
\addtobeamertemplate{alerted text begin}{}{%
  \setbeamercolor{block title}{parent=alerted text}%
}  
\makeatother

\begin{document}

\section{ABC}

\begin{frame}

\begin{alertenv}<+>
  \begin{theorem}[ABC]
    This is a theorem
  \end{theorem}
\end{alertenv}

  \begin{theorem}[DEF]
    This is a another theorem (not alerted).
  \end{theorem}

  Text.

  \begin{block}{Block title}
    A block with title.
  \end{block}

  Text.

  \begin{block}{}
    A block without title.
  \end{block}

\end{frame}

\end{document}

在此处输入图片描述

相关内容