将框架定理从 mdframed 包更改为 tcolorbox

将框架定理从 mdframed 包更改为 tcolorbox

我一直在笔记中使用 mdframed 包来编写框架定理。但是存在许多与间距相关的问题(例如,紧接着章节标题的框架间距行为不佳)和分页问题。我阅读了 stackexchange 中的许多问题,人们一直建议改用 tcolorbox 包。

我现在有以下框架环境。我想使用 tcolorbox 来生成相同的框(当然也是为了解决间距问题)。

%!TEX TS-program = pdflatex
\documentclass[hidelinks,10pt]{book}


\usepackage{adjustbox,amsmath,amsfonts,amssymb,amsthm,bm,booktabs,bussproofs,caption,color,csquotes,enumitem,etoc,etoolbox,float,geometry,graphicx,hyperref,lipsum,listings,mathtools,mleftright,moreenum,multicol,physics,relsize,subcaption,tablefootnote,tcolorbox,tikz,thmtools,url,wrapfig,xcolor}
\usepackage[utf8]{inputenc} 
\usepackage[english]{babel} 
\usepackage[pagestyles]{titlesec}
\usepackage[parfill]{parskip}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage[nodisplayskipstretch]{setspace}

\usetikzlibrary{calc,decorations.markings,shapes.callouts,arrows,intersections,cd,backgrounds}

\usepackage[tt=false]{libertine}
\usepackage[libertine]{newtxmath}

\geometry{left=2.4cm, right=2.4cm, top=2.4cm, bottom=2.0cm}
\linespread{1.1}

\newcounter{theorem}[chapter] 
\setcounter{theorem}{0}
\renewcommand{\thetheorem}{\thechapter.\arabic{theorem}}


% Box environment definition
% #1: environment name, #2: display name, #3: nobreak value (true/false)
\newcommand{\boxedstyle}[3]{%
    \newenvironment{#1}[2][]{%
        \refstepcounter{theorem}%
        \ifstrempty{##1}%
        {%
            \mdfsetup{%
                frametitle={%
                    \tikz[baseline=(current bounding box.east),outer sep=0pt]
                    \node[anchor=east,rectangle,fill=gray!20]
                    {\strut #2~\thetheorem};%
                }%
            }%
        }%
        {%
            \mdfsetup{%
                frametitle={%
                    \tikz[baseline=(current bounding box.east),outer sep=0pt]
                    \node[anchor=east,rectangle,fill=gray!20]
                    {\strut #2~\thetheorem.~##1};%
                }%
            }%
        }%
        \mdfsetup{
            innertopmargin=0pt,
            linecolor=gray!20,
            linewidth=2pt,
            topline=true,
            skipabove=15pt,
            nobreak=#3, % using the provided value
            frametitleaboveskip=\dimexpr-\ht\strutbox\relax
        }
        \begin{mdframed}[]\relax%
        \ifstrempty{##2}{}{\label{##2}}%
    }{%
        \end{mdframed}%
    }%
} 

\boxedstyle{theorem}{Theorem}{true}
\boxedstyle{longthm}{Theorem}{false}
\boxedstyle{lemma}{Lemma}{true}
\boxedstyle{proposition}{Proposition}{true}
\boxedstyle{corollary}{Corollary}{true}
\boxedstyle{example}{Example}{true}


\begin{document}

\newcommand{\Z}{\mathbb Z}
\begin{example}[Examples of Modules]{eg:modules}
    \begin{enumerate}
        \item Every Abelian group $G$ has a unique $\Z$-module structure: 
        \begin{center}
            $\forall\, n\in\Z\ \ \forall\, g\in G:\quad ng:=\underbrace{g+\cdots+g}_{n\text{ times}}$
        \end{center}
        This is because $\Z$ is initial in $\mathbf{Ring}$, so there is a unique ring homomorphism $\sigma: \Z \to \operatorname{Aut}(G)$. 
        
        In fact, the category $\Z$-$\mathbf{Mod}$ is just $\mathbf{Ab}$.
    \end{enumerate}
\end{example}

\subsection{Sub- and Quotient Modules}

\begin{proposition}[Kernels are Submodules]{}
    Suppose that $f: M \to N$ is an $R$-module homomorphism. Then $\ker f$ is a submodule of $M$.
\end{proposition}

An integral domain is called a Euclidean Domain (abbreviated ED) if it admits a Euclidean valuation.

\begin{theorem}[Euclidean Algorithm]{thm:euc_algr}
    Suppose that $R$ is a Euclidean domain. Let $a_1,a_2\in R\setminus\{0\}$ such that $v(a_1)\geqslant v(a_2)$. The Euclidean algorithm uniquely determines the sequences $q_i$ and $a_i$ of integers:
    \begin{align*}
        & a_1 = q_1a_2 + a_3\quad\quad\quad v(a_3)<v(a_2) \\
        & a_2 = q_1a_3 + a_4\quad\quad\quad v(a_4)<v(a_3) \\
        & a_3 = q_1a_4 + a_5\quad\quad\quad v(a_5)<v(a_4) \\
        &\cdots 
    \end{align*}
    The algorithm terminates at $a_k=0$ for some $k$. Then $a_{k-1}=\operatorname{gcd}(a_1,a_2)$.
\end{theorem}


\end{document}

以下是它生成的结果。请注意第 0.0.1 节之后的异常垂直间距。

在此处输入图片描述

相关内容