# How do we create an exercise environment like this:

How can we to create an exercise environment like this:

I tried:

\begin{tcolorbox}

\textbf{Câu 3}
Cho $x,y,z$ thỏa mãn $x^2+y^2+z^2=1.$ Chứng minh rằng
$$\dfrac{x^2}{1+2yz}+\dfrac{y^2}{1+2zx}+\dfrac{z^2}{1+2xy}\geqslant \dfrac{3}{5}$$

\end{tcolorbox}


But no success. I still can't not placing a colored box around "Câu 3"

• Please clarify what you're (still) trying to achieve. Is it (a) placing a colored box around "Câu 3" and (b) writing "Dien Bien" at the bottom right of the gray box?
– Mico
Dec 27, 2020 at 12:49
• @Mico Yes, I only can't not placing a colored box around "Câu 3". Dec 27, 2020 at 12:49

In the following MWE, I used a newly defined tcolorbox for the text in teh upper left corner. The symbol is contained in the fontawesome5 package and can be ccessed through \faToggleOn. Spacing around the text, height, width and color of the box can of course be adjusted to suit your needs.

To get rid of the outer box's frame, I used boxrule=0pt, frame hidden, to get corners with a 90° angle instead of rounded corners, I added sharp corners.

\documentclass{article}
\usepackage{amssymb}
\usepackage{fontawesome5}
\usepackage[most]{tcolorbox}

\definecolor{mycolor}{RGB}{0,128,128}
\newtcbox{\mybox}{on line,
colback=mycolor,
fontupper=\bfseries\color{white},
boxrule=0pt,
arc=5pt,
boxsep=0pt,
left=2pt,
right=2pt,
top=5pt,
bottom=5pt}

\begin{document}

\begin{tcolorbox}[boxrule=0pt, frame hidden, sharp corners]

\mybox{\faToggleOn\; Câu 3}
Cho $x,y,z$ thỏa mãn $x^2+y^2+z^2=1.$ Chứng minh rằng
$\dfrac{x^2}{1+2yz}+\dfrac{y^2}{1+2zx}+\dfrac{z^2}{1+2xy}\geqslant \dfrac{3}{5}$

\end{tcolorbox}

\end{document}


Updated version that automatically numbers the boxes within their \section:

\documentclass{article}
\usepackage{amssymb}
\usepackage{fontawesome5}
\usepackage[most]{tcolorbox}

\definecolor{mycolor}{RGB}{0,128,128}

\newtcbtheorem[auto counter, number within=section,]{mycau}{\faToggleOn\; Câu}%
{enhanced jigsaw,%
sharp corners,%
boxrule=0pt,
frame hidden,%
colbacktitle= mycolor,
boxed title style={boxrule=0pt,
frame hidden,
boxsep=0pt,
top=5pt,
bottom=5pt,
left=2pt,
right=2pt,
arc=5pt},
attach boxed title to top left={xshift=0.5cm,yshift=-8mm},
fonttitle=\color{white}\bfseries,%
before upper=\hspace{2.5cm}
}{th}

\begin{document}

\begin{mycau}{}{label}
Cho $x,y,z$ thỏa mãn $x^2+y^2+z^2=1.$ Chứng minh rằng
$\frac{x^2}{1+2yz}+\frac{y^2}{1+2zx}+\frac{z^2}{1+2xy}\geqslant \frac{3}{5}$
\end{mycau}

\end{document}

• Thank you very much! Could you make the black border disappears? Dec 27, 2020 at 13:01
• @tthnew: Sure, I'll add an update on that. Do you want rounded or sharp corners for the outer gray box? Dec 27, 2020 at 13:02
• Yes, I want in like a right angle (as the picture in my post). Thank you! Dec 27, 2020 at 13:03
• Now I'm trying to let it be "auto counter, number within=section", could you help me now dear sir? I tried " \renewcommand{\ta}{\mmbox{\,\faToggleOn\, Câu\,}} \newtcbtheorem[auto counter, number within=section]{khungx}{\ta}%{ boxrule=0pt,% colback=gray!7!white }{th}" but it doesn't work. Dec 27, 2020 at 14:03
• @tthnew: I have updated my answer accordingly. Probably this new version is closer to the expected output? Dec 27, 2020 at 14:28

The xcolor package, which is loaded automatically by the tcolorbox package, provides the macros \colorbox and \textcolor; they come in handy here.

\documentclass{article}
\usepackage[vietnamese]{babel}
\usepackage{amsmath,amssymb,tcolorbox,fontawesome5}

% optional: load suitable text and math fonts:
\usepackage{unicode-math}
\setmainfont{Fira Sans}
\setmathfont{Fira Math Regular}[Scale=MatchLowercase]

\begin{document}
\begin{tcolorbox}[boxrule=0pt]
\colorbox{teal}{\textcolor{white}{\bfseries\faToggleOn\ Câu 3}}
Cho $x,y,z$ thỏa mãn $x^2+y^2+z^2=1.$ Chứng minh rằng
$\frac{x^2}{1+2yz}+\frac{y^2}{1+2zx}+\frac{z^2}{1+2xy} \geqslant \frac{3}{5}$
\end{tcolorbox}
\end{document}

• Thanks, but how we can great something like circle, which in front of "Câu 3"? Dec 27, 2020 at 12:57
• I've added the toggle symbol and removed the black frame around the tcolorbox.
– Mico
Dec 27, 2020 at 13:06
• @Mico Should I type $x,y,z$ or $x$, $y$, $z$? Dec 27, 2020 at 15:18
• @minhthien_2016 - I guess the answer depends importantly on what "Cho" and "thỏa mãn" mean. Can you translate? (Sorry, my Vietnamese is nonexistent.)
– Mico
Dec 27, 2020 at 15:28
• "Cho" is mean "Let be given", and "thỏa mãn" is satifying. Let be given $x,y,z$ satifying $x^2+y^2+z^2=1.$ Prove that [ \frac{x^2}{1+2yz}+\frac{y^2}{1+2zx}+\frac{z^2}{1+2xy} \geqslant \frac{3}{5} ] Dec 27, 2020 at 15:32

Inspired by the answers of @leandriis and @Mico here is how you could combine tcolorbox with an exercise package like xsim:

\documentclass{article}
\usepackage[vietnamese]{babel}
\usepackage[T1]{fontenc}
\usepackage[margin=2cm]{geometry}
\usepackage{amssymb}
\usepackage{fontawesome}
\usepackage[most]{tcolorbox}
\usepackage{xsim}

\DeclareExerciseEnvironmentTemplate{custom}{%
\begin{tcolorbox}[boxrule = 0pt]
\tcbox[on line,colback=teal,colframe=teal,coltext=white,size=small]{%
\faToggleOn\sffamily\bfseries\
\XSIMmixedcase{\GetExerciseName}
\GetExerciseProperty{counter}%
}{\hfill\textbf{Điện Biên}\end{tcolorbox}}

\xsimsetup{
exercise/template = custom ,
exercise/name = Câu
}

\begin{document}

\begin{exercise}
Cho $x,y,z$ thỏa mãn $x^2+y^2+z^2=1$. Chứng minh rằng
$\frac{x^2}{1+2yz}+\frac{y^2}{1+2zx}+\frac{z^2}{1+2xy} \geqslant \frac{3}{5}$
\end{exercise}

\end{document}