答案1
可以使用“tcolorbox”包获得解决方案。有很多种可能性。我画了三种(在下面的例子中)。在第一部分中,我尝试坚持您希望的风格,为类似定理的环境设置单独的标题。
在第二部分中,构造比较简单;引理是直接使用手册中的示例获得的(几乎)。但是您没有单独的标题行。
手册第 339 页还指出了另一种可能性,即使用\newtcbtheorem
,但交叉引用的标签和定义很奇怪。我个人不喜欢它。
\documentclass[11pt, a4paper]{article}
\usepackage[top=105pt, bottom=75pt, left=75pt, right=75pt]{geometry}
\setlength{\headsep}{15pt}
\setlength{\footskip}{45pt}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{amsmath, amssymb, amsthm}
\usepackage{ifthen}
\usepackage{tikz}
\usetikzlibrary{calc}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tcolorbox}
\tcbuselibrary{skins, breakable}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% with separate title
\xdefinecolor{thmTopColor}{RGB}{102, 102, 238}
\xdefinecolor{thmBackColor}{RGB}{245, 245, 255} % white
\newenvironment{thmbox}[1]{%
\tcolorbox[%
empty,
parbox=false,
noparskip,
enhanced,
breakable,
sharp corners,
boxrule=-1pt,
left=2ex,
right=0ex,
top=0ex,
boxsep=1ex,
before skip=2.5ex plus 2pt,
after skip=2.5ex plus 2pt,
colback=thmBackColor,
colframe=white,
coltitle=black,
colbacktitle=thmBackColor,
fonttitle=\bfseries,
title=#1,
titlerule=1pt,
titlerule style=thmTopColor,
overlay unbroken and last={%
\draw[color=thmTopColor, line width=1.25pt]
($(frame.north west)+(.5em, -4.1ex)$)
-- ($(frame.south west)+(.5em, 1ex)$) -- ++(2em, 0);
}]
}{\endtcolorbox}
\newenvironment{thmb}[1][]{% before
\refstepcounter{thm}%
\ifthenelse{\equal{#1}{}}{%
\begin{thmbox}{Theorem \thethm.}\itshape\hspace{-.75ex}%
}{%
\begin{thmbox}{Theorem \thethm%
\hspace{.75ex}(\textnormal{#1}).}\itshape\hspace{-.75ex}
}}
{\end{thmbox}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% simple forms
% 1
\newtheorem{thm}{Theorem}[section]
\theoremstyle{definition}
\newtheorem{definition}[thm]{Definition}
\newenvironment{noticeB}[1][]{%
\ifthenelse{\equal{#1}{}}{%
\colorlet{cbackground}{white}
}{\colorlet{cbackground}{#1}}
\tcolorbox[%
notitle,
empty,
enhanced, % delete the edge of the bottom page for a broken box
breakable,
coltext=black,
colback=cbackground,
fontupper=\rmfamily,
parbox=false,
noparskip,
sharp corners,
boxrule=-1pt, % width of the box' edges
frame hidden,
left=.5\parindent, % inner space from text to the left edge
right=.5\parindent,
top=5pt,
bottom=5pt,
% boxsep=0pt,
before skip=2.5ex plus 2pt,
after skip=2.5ex plus 2pt,
borderline west = {1.5pt}{-0.1pt}{blue!30!black}, % second argument = offset
overlay unbroken and last={%
\draw[color=black, line width=1.25pt]
($(frame.south west)+(1.pt, -0.1pt)$) -- ++(2em, 0);
}
]}
{\endtcolorbox}
\newenvironment{thmB}{\begin{thm}\begin{noticeB}[blue!50!black!5]}
{\end{noticeB}\end{thm}}
\newenvironment{definitionB}{\begin{definition}\begin{noticeB}}{%
\end{noticeB}\end{definition}}
%2
\newtheorem{lem}[thm]{Lemma}% from 'amsthm'
\tcolorboxenvironment{lem}{%
enhanced jigsaw,
boxrule=-1pt,
colframe=white,
borderline west={2pt}{0pt}{orange}, % second argument is the offset
interior hidden,
breakable,
before skip=2.5ex plus 2pt,
after skip=2.5ex plus 2pt
}
\begin{document}
\section{Based on \texttt{tcolorbox} with titles}
\begin{thmb}
\label{th:test}
\lipsum[5]
\end{thmb}
\lipsum[1]
\begin{thmb}[Anonymous]
\label{th:test2}
\lipsum[6]
\end{thmb}
Can we make a reference to Theorem \ref{th:test}? Yes we can.
\section{With simpler definitions for the theorem-like environmants}
\begin{definitionB}
\lipsum[1]
\end{definitionB}
\lipsum[2]
\begin{thmB}
\lipsum[5]
\end{thmB}
\lipsum[4]
\begin{lem}[from \texttt{tcolorbox} manual]
\lipsum[7]
\end{lem}
\end{document}