每种定理类型使用不同的颜色阴影

每种定理类型使用不同的颜色阴影

互联网上有很多关于如何在 LaTeX 中为定理着色的评论,其中很多都超出了我的理解复杂程度。

目前,我使用了一种相当简单的模式,它允许我为定理、引理等着色,但全部使用相同的颜色。这种模式是否可以轻松扩展,以允许引理、推论、定义、示例等都具有自己的颜色?例如,引理为浅蓝色,定理为浅粉色等。代码如下。

我不太理解为什么这样做有效,但似乎所有着色环境都使用相同的全局值。如果我可以在每个环境中shadecolor局部定义不同的值,那么可能会有希望。1) 我不知道这个概念是否有意义,2) 我不知道语法。shadecolor\newenvironment

\documentclass[a4paper]{article}

\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{framed}
\theoremstyle{plain}% default
\newtheorem{prototheorem}{Theorem}[section]
\colorlet{shadecolor}{orange!15}

\newenvironment{theorem}
   {\begin{shaded}\begin{prototheorem}}
   {\end{prototheorem}\end{shaded}}

\newtheorem{protolemma}[prototheorem]{Lemma}
\newenvironment{lemma}
   {\begin{shaded}\begin{protolemma}}
   {\end{protolemma}\end{shaded}}

\newtheorem{protocorollary}[prototheorem]{Corollary}
\newenvironment{corollary}
   {\begin{shaded}\begin{protocorollary}}
   {\end{protocorollary}\end{shaded}}

\theoremstyle{definition}
\newtheorem{protonotation}{Notation}[section]
\newenvironment{notation}
   {\begin{shaded}\begin{protonotation}}
   {\end{protonotation}\end{shaded}}

\newtheorem{protoexample}{Example}[section]
\newenvironment{example}
   {\begin{shaded}\begin{protoexample}}
   {\end{protoexample}\end{shaded}}

\newtheorem{protodefinition}{Definition}[section]
\newenvironment{definition}
   {\begin{shaded}\begin{protodefinition}}
   {\end{protodefinition}\end{shaded}}

\newcommand{\powerset}[1]{\rho(#1)}

\begin{document}

\section{Introduction}

\begin{theorem}
  \label{theorem.188}  %% used
  If $V \subseteq U$, and if $F$ is a set of binary functions defined on
  $U$, then there exists a unique $clos_F(V)$ and it is closed under $F$.
\end{theorem}
\begin{proof}
  First we show, by construction, that at least one closed superset of $V$ exists.
  Define a sequence $\{\Phi_n\}_{n=0}^{\infty}$ of sets as follows:
  \begin{itemize}
  \item $\Phi_0 = V$
  \item If $i>0$, then $\Phi_{i} = \Phi_{i-1} \cup \bigcup\limits_{f \in F}\{f(x,y) \mid x,y\in \Phi_{i-1}\}$
  \end{itemize}
  Define the set $\Phi = \bigcup\limits_{i=0}^{\infty}\Phi_i$. We know
  that $V = \Phi_0 \subseteq \bigcup\limits_{i=0}^{\infty}\Phi_i$.  Next,
  let $\alpha \in \Phi$, $\beta \in \Phi$, $f \in F$; take $n \geq 0$
  such that $\alpha,\beta \in \Phi_n$.  By definition
  $f(\alpha,\beta) \in \Phi_{n+1} \subseteq \Phi$.  Thus $\Phi$ closed under $F$.
\end{proof}

\begin{example} \label{example.363}
  Let $V= \{\{1,2\},\{2,3\}\}$, and $F$ but the set containing the
  set-union and set-intersection operations, denoted
  $F=\{\cup,\cap\}$.  Then $clos_F(V) =
  \{\emptyset,\{1,2\},\{2\},\{2,3\},\{1,2,3\}\}$, because if we take $\alpha,
  \beta \in \{\emptyset,\{1,2\},\{2\},\{2,3\},\{1,2,3\}\}$ then both $\alpha
  \cup \beta$ and $\alpha \cap \beta$ are also therein.

\end{example}

\begin{definition}
  \label{def.vhat}
  If $V\subseteq U$, and $F$ is the set of three primitive set operations
  union, intersection, and relative complement, ($F = \{\cup, \cap, \setminus \}$) then we denote
  $clos_F(V)$ simply by $\sigma(V)$ and call it the \emph{Sigma algebra} of $V$.  Moreover,
  each element of $\sigma(V)$ is called a \emph{Boolean combination} of elements of $V$.
\end{definition}

\section{Conclusion}

\begin{corollary}
  \label{corol.467}
  If $V\subseteq U$, $\sigma(V)$ exists and is unique.
\end{corollary}
\begin{proof}
  Simple application of Theorem~\ref{theorem.188}.
\end{proof}
\begin{example}
  Let  $V= \{\{1,2\},\{2,3\}\}$ as in Example~\ref{example.363}.\\
  $\sigma(V)= \{\emptyset,\{1\},\{2\},\{3\},\{1,2\},\{1,3\},\{2,3\},\{1,2,3\}\}$.
   $\sigma(V)= \powerset{\{1,2,3\}}$.
\end{example}
\end{document}

答案1

只需\colorlet{shadecolor}{orange!15}在不同的环境中定义,使用相应的颜色即可。详情如下:

  • 旧代码:

    \colorlet{shadecolor}{orange!15} % global definition
    \newenvironment{lemma}
       {\begin{shaded}\begin{protolemma}}
       {\end{protolemma}\end{shaded}}
    
  • 新代码:

    \newenvironment{lemma}
       {\colorlet{shadecolor}{blue!15}\begin{shaded}\begin{protolemma}} % light blue for lemmas only
       {\end{protolemma}\end{shaded}}
    

完整示例:

\documentclass[a4paper]{article}

\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{framed}
\theoremstyle{plain}% default
\newtheorem{prototheorem}{Theorem}[section]

\newenvironment{theorem}
   {\colorlet{shadecolor}{orange!15}\begin{shaded}\begin{prototheorem}}
   {\end{prototheorem}\end{shaded}}

\newtheorem{protolemma}[prototheorem]{Lemma}
\newenvironment{lemma}
   {\colorlet{shadecolor}{blue!15}\begin{shaded}\begin{protolemma}}
   {\end{protolemma}\end{shaded}}

\newtheorem{protocorollary}[prototheorem]{Corollary}
\newenvironment{corollary}
   {\colorlet{shadecolor}{pink!15}\begin{shaded}\begin{protocorollary}}
   {\end{protocorollary}\end{shaded}}

\theoremstyle{definition}
\newtheorem{protonotation}{Notation}[section]
\newenvironment{notation}
   {\colorlet{shadecolor}{green!15}\begin{shaded}\begin{protonotation}}
   {\end{protonotation}\end{shaded}}

\newtheorem{protoexample}{Example}[section]
\newenvironment{example}
   {\colorlet{shadecolor}{red!15}\begin{shaded}\begin{protoexample}}
   {\end{protoexample}\end{shaded}}

\newtheorem{protodefinition}{Definition}[section]
\newenvironment{definition}
   {\colorlet{shadecolor}{black!15}\begin{shaded}\begin{protodefinition}}
   {\end{protodefinition}\end{shaded}}

\newcommand{\powerset}[1]{\rho(#1)}

\begin{document}

\section{Introduction}

\begin{theorem}
  \label{theorem.188}  %% used
  If $V \subseteq U$, and if $F$ is a set of binary functions defined on
  $U$, then there exists a unique $clos_F(V)$ and it is closed under $F$.
\end{theorem}
\begin{example} \label{example.363}
  Let $V= \{\{1,2\},\{2,3\}\}$, and $F$ but the set containing the
  set-union and set-intersection operations, denoted
  $F=\{\cup,\cap\}$.  Then $clos_F(V) =
  \{\emptyset,\{1,2\},\{2\},\{2,3\},\{1,2,3\}\}$, because if we take $\alpha,
  \beta \in \{\emptyset,\{1,2\},\{2\},\{2,3\},\{1,2,3\}\}$ then both $\alpha
  \cup \beta$ and $\alpha \cap \beta$ are also therein.
\end{example}
\begin{lemma}
  \label{def.vhat}
  If $V\subseteq U$, and $F$ is the set of three primitive set operations
  union, intersection, and relative complement, ($F = \{\cup, \cap, \setminus \}$) then we denote
  $clos_F(V)$ simply by $\sigma(V)$ and call it the \emph{Sigma algebra} of $V$.  Moreover,
  each element of $\sigma(V)$ is called a \emph{Boolean combination} of elements of $V$.
\end{lemma}

\section{Conclusion}

\begin{corollary}
  \label{corol.467}
  If $V\subseteq U$, $\sigma(V)$ exists and is unique.
\end{corollary}
\begin{definition}
  Let  $V= \{\{1,2\},\{2,3\}\}$ as in Example~\ref{example.363}.\\
  $\sigma(V)= \{\emptyset,\{1\},\{2\},\{3\},\{1,2\},\{1,3\},\{2,3\},\{1,2,3\}\}$.
   $\sigma(V)= \powerset{\{1,2,3\}}$.
\end{definition}
\end{document}

在此处输入图片描述

相关内容