tcolorbox 定义

tcolorbox 定义

我怎样才能使灰色的上框与黄色的下框相似。我的意思是我希望定义计数器与章节号一起工作。

我尝试了代码,黄色框正是我想要的,但定义不是自动的。

\documentclass[a4paper]{article}
\usepackage[most]{tcolorbox}


\newenvironment{BoxDefinition}[2]{%
\begin{center}
    \begin{tcolorbox}
        [enhanced jigsaw,breakable,pad at break*=1mm,enlarge left by=8mm,
        colback=yellow!10!white,boxrule=0pt,frame hidden, 
        borderline west={1.5mm}{-2mm}{red}]
        \textcolor{red}{\textit{#1}} #2}    
    {\end{tcolorbox}    
\end{center}}



\newtcbtheorem[auto counter]{mydef}{Definition}{%
lower separated=false,
colback=white!80!gray,
colframe=white!20!black,fonttitle=\bfseries,
colbacktitle=white!30!gray,
coltitle=black,
enhanced,
attach boxed title to top left={xshift=0.5cm,yshift=-2mm},
}{met}


\begin{document}



\begin{mydef}[colbacktitle={yellow}]{THEDEF}{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis, nunc sed vestibulum dapibus, ex velit vulputate lorem, sit amet sollicitudin justo mauris vel augue. Donec egestas elit odio, quis faucibus ligula ultricies vel. Aenean laoreet massa vel velit pellentesque, nec scelerisque sapien accumsan. Curabitur nisl lacus, suscipit ac tincidunt ut, molestie ut neque. Pellentesque neque diam, mollis in neque at, interdum semper lorem. Etiam vitae massa a leo facilisis maximus. Donec lacus ipsum, luctus vitae suscipit vitae, vehicula vel metus. Pellentesque nisi metus, maximus sed turpis ac, pharetra tempor nunc. Donec in magna luctus, volutpat tellus vitae, tincidunt lacus. Praesent turpis mi, vehicula pharetra erat et, finibus congue ligula. Sed id tortor arcu. 
 \end{mydef}

\begin{BoxDefinition}{Definition 1: (THEDEF)}{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis, nunc sed vestibulum dapibus, ex velit vulputate lorem, sit amet sollicitudin justo mauris vel augue. Donec egestas elit odio, quis faucibus ligula ultricies vel. Aenean laoreet massa vel velit pellentesque, nec scelerisque sapien accumsan. Curabitur nisl lacus, suscipit ac tincidunt ut, molestie ut neque. Pellentesque neque diam, mollis in neque at, interdum semper lorem. Etiam vitae massa a leo facilisis maximus. Donec lacus ipsum, luctus vitae suscipit vitae, vehicula vel metus. Pellentesque nisi metus, maximus sed turpis ac, pharetra tempor nunc. Donec in magna luctus, volutpat tellus vitae, tincidunt lacus. Praesent turpis mi, vehicula pharetra erat et, finibus congue ligula. Sed id tortor arcu. 
 \end{BoxDefinition}


\end{document}

在此处输入图片描述

答案1

您需要将tcolorbox中的方面定义插入并复制number within=chapter到您的定理中。initialization optionsBoxDefinitionmydef

\documentclass[a4paper]{book}
\usepackage[most]{tcolorbox}


\newenvironment{BoxDefinition}[2]{%
\begin{center}
    \begin{tcolorbox}
        [enhanced jigsaw,breakable,pad at break*=1mm,enlarge left by=8mm,
        colback=yellow!10!white,boxrule=0pt,frame hidden, 
        borderline west={1.5mm}{-2mm}{red}]
        \textcolor{red}{\textit{#1}} #2}    
    {\end{tcolorbox}    
\end{center}}



\newtcbtheorem[auto counter, number within=chapter]{mydef}{Definition}{%
enhanced, breakable, pad at break*=1mm, enlarge left by =8mm,
colback=yellow!10!white,, boxrule=0pt, frame hidden, borderline west={1.5mm}{-2mm}{red},
colframe=white!20!black,fonttitle=\bfseries,
attach title to upper={\ },
coltitle=red, fonttitle=\itshape,
description delimiters={(}{)}
}{met}


\begin{document}


\chapter{One}

\begin{mydef}[colbacktitle={yellow}]{THEDEF}{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis, nunc sed vestibulum dapibus, ex velit vulputate lorem, sit amet sollicitudin justo mauris vel augue. Donec egestas elit odio, quis faucibus ligula ultricies vel. Aenean laoreet massa vel velit pellentesque, nec scelerisque sapien accumsan. Curabitur nisl lacus, suscipit ac tincidunt ut, molestie ut neque. Pellentesque neque diam, mollis in neque at, interdum semper lorem. Etiam vitae massa a leo facilisis maximus. Donec lacus ipsum, luctus vitae suscipit vitae, vehicula vel metus. Pellentesque nisi metus, maximus sed turpis ac, pharetra tempor nunc. Donec in magna luctus, volutpat tellus vitae, tincidunt lacus. Praesent turpis mi, vehicula pharetra erat et, finibus congue ligula. Sed id tortor arcu. 
 \end{mydef}

\begin{BoxDefinition}{Definition 1: (THEDEF)}{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin venenatis, nunc sed vestibulum dapibus, ex velit vulputate lorem, sit amet sollicitudin justo mauris vel augue. Donec egestas elit odio, quis faucibus ligula ultricies vel. Aenean laoreet massa vel velit pellentesque, nec scelerisque sapien accumsan. Curabitur nisl lacus, suscipit ac tincidunt ut, molestie ut neque. Pellentesque neque diam, mollis in neque at, interdum semper lorem. Etiam vitae massa a leo facilisis maximus. Donec lacus ipsum, luctus vitae suscipit vitae, vehicula vel metus. Pellentesque nisi metus, maximus sed turpis ac, pharetra tempor nunc. Donec in magna luctus, volutpat tellus vitae, tincidunt lacus. Praesent turpis mi, vehicula pharetra erat et, finibus congue ligula. Sed id tortor arcu. 
 \end{BoxDefinition}


\end{document}

在此处输入图片描述

相关内容