Leftbar 定理环境,左侧栏颜色可变

Leftbar 定理环境,左侧栏颜色可变

我正在写一些讲义,我想要一个用于定理和定义的左栏环境,并且左栏和内部的颜色可以更改(白色或灰色)。

我找到了这个代码:

\documentclass[10pt,letterpaper]{amsbook}
\usepackage{amsthm}
\usepackage{xcolor}
\definecolor{lightgray}{gray}{0.90}

\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[section]
%\numberwithin{theorem}{subsection} % important bit
\usepackage{framed}
\renewenvironment{leftbar}[1][\hsize]
{% 
\def\FrameCommand 
{%

    {\hspace{-3pt}\color{black}\vrule width 3pt}%
    \hspace{0pt}%must no space.
    \fboxsep=\FrameSep\colorbox{lightgray}%
}%
\MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
}
{\endMakeFramed}
\setlength{\FrameSep}{0pt}
\begin{document}

\begin{leftbar}
\begin{theorem}
Fun Math
\end{theorem}
\end{leftbar}
\begin{theorem}
Fun Math
\end{theorem}
\end{document}

但我不知道如何更改每个环境的左栏颜色(绿色表示定义,红色表示定理)甚至内部颜色。我想要一些不必\begin{leftbar} ... \end{leftbar}每次都写的东西。

答案1

正在使用彩色盒子一个选项?它提供了强大的定理环境,例如,你可以生成

在此处输入图片描述

使用代码:

\documentclass[10pt,letterpaper]{amsbook}
\usepackage{amsthm}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{skins}

\newtcbtheorem[number within=section]{defn}{Definition}%
   {theorem style=plain,enhanced,colframe=blue!50!black,colback=yellow!20!white,
    coltitle=red!50!black,fonttitle=\upshape\bfseries,fontupper=\itshape,
    drop fuzzy shadow=blue!50!black!50!white,boxrule=0.4pt,
    borderline west={1mm}{0pt}{green}
   }{D}
\newtcbtheorem[number within=section]{theorem}{Theorem}%
   {theorem style=plain,enhanced,colframe=blue!50!black,colback=yellow!20!white,
    coltitle=red!50!black,fonttitle=\upshape\bfseries,fontupper=\itshape,
    drop fuzzy shadow=blue!50!black!50!white,boxrule=0.4pt,
    borderline west={1mm}{0pt}{red}
   }{T}

\begin{document}

  \begin{defn}{defn title}{mydef}
    Fun Math
  \end{defn}

  A reference \ref{D:mydef}

  \begin{theorem}{theorem title}{mytheorem}
    Fun Math
  \end{theorem}

  A reference \ref{T:mytheorem}

\end{document}

编辑

根据评论中的要求,您可以通过将框架边框设置为与背景相同的颜色来删除它,并且可以通过设置将分号更改:为。这给出:.terminator sign

在此处输入图片描述

修改后的代码如下:

\documentclass[10pt,letterpaper]{amsbook}
\usepackage{amsthm}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\tcbuselibrary{skins}

\newtcbtheorem[number within=section]{defn}{Definition}%
   {theorem style=plain,enhanced,colframe=yellow!20!white,colback=yellow!20!white,
    coltitle=red!50!black,fonttitle=\upshape\bfseries,fontupper=\itshape,
    drop fuzzy shadow=blue!50!black!50!white, terminator sign={.},
    borderline west={1mm}{0pt}{green}
   }{D}
\newtcbtheorem[number within=section]{theorem}{Theorem}%
   {theorem style=plain,enhanced,colframe=yellow!20!white,colback=yellow!20!white,
    coltitle=red!50!black,fonttitle=\upshape\bfseries,fontupper=\itshape,
    drop fuzzy shadow=blue!50!black!50!white,terminator sign={.},
    borderline west={1mm}{0pt}{red}
   }{T}

\begin{document}

  \begin{defn}{defn title}{mydef}
    Fun Math
  \end{defn}

  A reference \ref{D:mydef}

  \begin{theorem}{theorem title}{mytheorem}
    Fun Math
  \end{theorem}

  A reference \ref{T:mytheorem}

\end{document}

您可能还想删除drop fuzzy shadow=blue!50!black!50!white以消除定理框下的“阴影”。

相关内容