0

How can I make the grey upper box similar to the yellow bottom box. I mean I want the definition counter works with the chapter number.

I tried a code and the yellow box is exactly what I want but the definition is not automatic.

\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}

enter image description here

2
  • If the theorem box is like you want, just add option counter within=chapter after autocounter.
    – Ignasi
    Commented Jan 22, 2021 at 15:28
  • true. But how can I style the theorem to be like the yellow box?
    – OOzy Pal
    Commented Jan 23, 2021 at 9:23

1 Answer 1

0

You need to insert number within=chapter into initialization options and copy aspect definition from BoxDefinition tcolorbox into your mydef theorem.

\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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .