答案1
这很容易tcolorbox
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage[many]{tcolorbox}
\newtheorem{theorem}{Theorem}[section]
\tcolorboxenvironment{theorem}{
colback=blue!5!white,
boxrule=0pt,
boxsep=1pt,
left=2pt,right=2pt,top=2pt,bottom=2pt,
oversize=2pt,
sharp corners,
before skip=\topsep,
after skip=\topsep,
}
\begin{document}
\section{Title}
Some text
\begin{theorem}
If $f$ is integrable on $[a,b]$, then it holds that
\[
\lim_{n\to\infty}\frac{b-a}{n}\sum_{k=1}^n f\Bigl(a+k\cdot\frac{b-a}{n}\Bigr)
=\int_a^b f(x)\,dx
\]
\end{theorem}
\begin{theorem}[Again]
If $f$ is integrable on $[a,b]$, then it holds that
\[
\lim_{n\to\infty}\frac{b-a}{n}\sum_{k=1}^n f\Bigl(a+k\cdot\frac{b-a}{n}\Bigr)
=\int_a^b f(x)\,dx
\]
\end{theorem}
\end{document}
请注意,您仍然可以使用可选参数。
答案2
这个怎么样?每个细节都以内联方式描述。
\documentclass{article}
\usepackage{amsthm,tcolorbox,xcolor,lipsum} % lipsum only needed for some blindtext.
\newtheorem{mytheorem}{Theorem}[section] % Create new theorem called 'Theorem'.
\newenvironment{mycolortheorem}[1][]{% % Create new environment which wraps our Theorem into a tcolorbox.
\begin{tcolorbox}[colback=blue!5!white,% Background color.
width=\dimexpr\linewidth+10pt\relax,% Allow your box to be bigger than \linewidth ...
enlarge left by=-5pt,% ... in order to have the text properly aligned. ...
enlarge right by=-5pt,% ... Note that boxsep = -enlargeLeft = -enlargeRight = 0.5*enlargement of width. ...
boxsep=5pt,% ... This is necessary to keep everything good looking.
left=0pt,% Avoid extra space on the left, ...
right=0pt,% ... right, ...
top=0pt,% ... top, ...
bottom=0pt,% ... and bottom.
arc=0pt,% Corners not rounded.
boxrule=0pt,% No boxrule.
colframe=white]{}{}% Make rest of the boxrule invisible.
\ifstrempty{#1}{% If you didn't specify the optional argument of Theorem ...
\begin{mytheorem}% ... then open a normal Theorem ...
}{% ... else ...
\begin{mytheorem}[#1]% ... open a Theorem and use the optional argument.
}%
}{%
\end{mytheorem}% Close every environment.
\end{tcolorbox}%
}
\begin{document}
\lipsum[1]
\begin{mycolortheorem}[named Theorem]
\lipsum[2]
\end{mycolortheorem}
\begin{mycolortheorem}
unnamed theorem.
\begin{equation}
1+1=2
\end{equation}
\end{mycolortheorem}
\lipsum[3]
\end{document}
答案3
我认为您可以使用框架包。
\documentclass{article}
\usepackage{framed}
\usepackage{xcolor}
\usepackage{lipsum}
\begin{document}
\colorlet{shadecolor}{gray!10}
\begin{shaded}
\noindent\textbf{Theorem 1.} \lipsum[3]
\end{shaded}
\end{document}