How can we to create an exercise environment like this: enter image description here

I tried



But it wasn't success.

  • 2
    The tcolorbox package might be useful.
    – leandriis
    Commented Dec 26, 2020 at 8:48

1 Answer 1


In the following example, I used \newtcbtheorem from the tcolorbox package. Spacing, colors, numbering scheme and more can of course be adjusted further to suit your needs:

enter image description here


\newtcbtheorem[auto counter, number within=chapter,]{mydef}{Definition}%
              {enhanced jigsaw,% 
               sharp corners,%
               borderline north={2pt}{0pt}{orange},%
               borderline south={2pt}{0pt}{orange},%
               theorem style=plain


\chapter{chapter title}


  • Thanks very much, if I want to change 1.1 to 2.1 (or any other number), how could I do that?
    – NKellira
    Commented Dec 26, 2020 at 10:42
  • Depends on what "2" represents here. In the example code, "1.1" stands for "chapter 1.definition 1" as I guessed, the first number was the chapter number. If that's not the case, please explain, what the first of the two numbers actually stands for.
    – leandriis
    Commented Dec 26, 2020 at 10:46
  • Because I want to write for a post, which not any chapter there.
    – NKellira
    Commented Dec 26, 2020 at 12:13
  • But what does the first number correspond to? A section, an exercise,...? Does it have any meaning? What does "post" refer to in this context? Please explain.
    – leandriis
    Commented Dec 26, 2020 at 12:14
  • 1
    If you number a definition using "2.1" and "2" is the section number and "1" is the subsection number, where is the definition's number? Wouldn't you need a format such as "2.1.3" for the third definition in the first subsection of the second section? If that's the output you want, using number within=subsection instead of number within=chapter should work.
    – leandriis
    Commented Dec 26, 2020 at 12:25

You must log in to answer this question.

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