如何让文本框使用定理环境的编号?

如何让文本框使用定理环境的编号?

我想要制作文本框,比如说用于定理的文本框,它呈现为编号文本框,尊重 amsart 类模板中其他环境(定义、定理等)的编号。

例如,如果我使用 amsart 类中预定义的 Definition 环境来创建 Definition 1.3,那么我想随后为定理创建一个文本框,并将其呈现为定理 1.4。

以下有效,但由于某种原因,应该放入框中的文本部分出现在围绕框标题的小框中。

\documentclass{amsart}
\usepackage{tcolorbox}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}

\newtcbtheorem[use counter*=theorem]{mytheo}{Theorem}{%
    enhanced jigsaw,
    colback=gray!20!white,%
    colframe=gray!80!black,
    size=small,
    boxrule=1pt,
    title=\textbf{Theorem},
    halign title=flush center,
    coltitle=black,
    breakable,
    drop shadow=black!50!white,
    attach boxed title to top left={xshift=0.5cm,yshift=-\tcboxedtitleheight/2,yshifttext=-\tcboxedtitleheight/2},
    minipage boxed title=2.5cm,
    boxed title style={%
        colback=white,
        size=fbox,
        boxrule=1pt,
        boxsep=2pt,
        underlay={%
            \coordinate (dotA) at ($(interior.west) + (-0.5pt,0)$);
            \coordinate (dotB) at ($(interior.east) + (0.5pt,0)$);
            \begin{scope}
                \clip (interior.north west) rectangle ([xshift=3ex]interior.east);
                \filldraw [white, blur shadow={shadow opacity=60, shadow yshift=-.75ex}, rounded corners=2pt] (interior.north west) rectangle (interior.south east);
            \end{scope}
            \begin{scope}[gray!80!black]
                \fill (dotA) circle (2pt);
                \fill (dotB) circle (2pt);
            \end{scope}
        },
    },
    #1,
}
{th}

答案1

您缺少一些 tcolobox 和 tikz 库。

\documentclass{amsart}
\usepackage{tcolorbox}

\tcbuselibrary{skins} % for attached boxed title to top left,  minipage boxed title, boxed title style, enhanced jigsaw, drop shadow,
\tcbuselibrary{theorems} % for the `\newtcbstheorem` macro
\tcbuselibrary{breakable} % for the breakable option
\usetikzlibrary{shadows.blur} % for the 'blur shadow' option in the underlay

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}

\newtcbtheorem[use counter*=theorem]{mytheo}{Theorem}{%
    enhanced jigsaw,
    colback=gray!20!white,
    colframe=gray!80!black,
    size=small,
    boxrule=1pt,
    title=\textbf{Theorem},
    halign title=flush center,
    coltitle=black,
    breakable,
    drop shadow=black!50!white,
    attach boxed title to top left={xshift=0.5cm,yshift=-\tcboxedtitleheight/2,yshifttext=-\tcboxedtitleheight/2},
    minipage boxed title=2.5cm,
    boxed title style={%
        colback=white,
        size=fbox,
        boxrule=1pt,
        boxsep=2pt,
        underlay={%
            \coordinate (dotA) at ($(interior.west) + (-0.5pt,0)$);
            \coordinate (dotB) at ($(interior.east) + (0.5pt,0)$);
            \begin{scope}
                \clip (interior.north west) rectangle ([xshift=3ex]interior.east);
                \filldraw [white, blur shadow={shadow opacity=60, shadow yshift=-.75ex}, rounded corners=2pt] (interior.north west) rectangle (interior.south east);
            \end{scope}
            \begin{scope}[gray!80!black]
                \fill (dotA) circle (2pt);
                \fill (dotB) circle (2pt);
            \end{scope}
        },
    },
    #1,
}
{th}

\begin{document}
    \section{Test}
    
    \begin{theorem}
        this is a theorem
    \end{theorem}
    
    \begin{mytheo}{}{} % #1 = env name, #2 = Title, #3 = label 
    this is a boxed theorem
    \end{mytheo}
\end{document}

在此处输入图片描述

如果您不确定彩色框需要哪些确切的库,建议使用mosttcolorbox 包的选项,即写入\usepackage[most]{tcolorbox}而不是\usepackage{tcolorbox}它将加载所有常用的库。

答案2

由于您没有提供完整版本MWE,我使用了类文件amsbook,完整版本MWE如下:

\documentclass{amsbook}
\usepackage{lipsum}
\newtheorem{definition}{Definition}[chapter]
\newtheorem{theorem}[definition]{Theorem}
\begin{document}

\chapter{Test}

\begin{definition}
Test
\end{definition}

\begin{theorem}
Test
\end{theorem}

\end{document}

在此处输入图片描述

相关内容