[Tex/LaTex] Draw a box with tcolorbox

tcolorbox

I'm trying to draw something like the following:

enter image description here

but with my following ( note that i'm tired with tcolorbox)

Code :

\documentclass{article}


\usepackage{amsmath,amsfonts,amssymb}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}

\usepackage[margin=1.5cm]{geometry}

\tcbset{
    lemmastyle/.style={enhanced, colback=white, colframe=black, arc=0pt, 
                       fonttitle=\bfseries, description color=Maroon,  
                       colbacktitle=white, coltitle=black,    
                       top=\tcboxedtitleheight,
                       boxed title style={arc=0pt},
                       attach boxed title to top left={yshift=-\tcboxedtitleheight/1, 
                                                                                                                                                                                                                                                                                                                                }%
                      },
}

\newtcbtheorem{myLemma1}{Question :}{lemmastyle}{thm}


\usepackage{pifont}
\usepackage{fancybox}

\begin{document}
\begin{tcolorbox}[width=\textwidth, enhanced,  valign=center, colback=white, colframe=black, sharp corners, shadow={0pt}{0pt}{0mm}{black},boxrule=0.5pt]
\textbf{Question 1~: Area of the region bounded by the curves $y=x^2+2, y=-x, x=0$ and $x=1$ is}
\[  \dfrac{7}{10} \]
\end{tcolorbox}
\begin{tcolorbox}[width=\textwidth, enhanced,  valign=center, colback=white, colframe=black, sharp corners, shadow={0pt}{0pt}{0mm}{black},boxrule=0.5pt]
\textbf{Question 2~:}
\end{tcolorbox}


\begin{myLemma1}{}{}
\textbf{ Area of the region bounded by the curves $y=x^2+2, y=-x, x=0$ and $x=1$ is \[ \dfrac{7}{10}\] }
\end{myLemma1}

\end{document}

I got this

output:

enter image description here

  • Could someone please show me how to set up a tcolorbox environment to get the box I want?

Best Answer

You could do something like this (but be careful not to add a \par at the begin, as this will remove the effect of the hangindent):

\documentclass{article}


\usepackage{amsmath,amsfonts,amssymb}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage[margin=1.5cm]{geometry}

\tcbset{
    lemmastyle/.style={enhanced, colback=white, colframe=black, arc=0pt,
                       fonttitle=\bfseries, description color=Maroon,
                       colbacktitle=white, coltitle=black,
                       top=\tcboxedtitleheight,
                       boxed title style={arc=0pt},
                       before title=\strut,
                       attach boxed title to top left={yshift=-\tcboxedtitleheight/1},
                       before upper={\vspace{\dimexpr-\tcboxedtitleheight+\dp\strutbox-0.8pt}\par\hangindent\tcboxedtitlewidth\hangafter-2},                       
                      },
}

\newtcbtheorem{myLemma1}{Question :}{lemmastyle}{thm}

\begin{document}

\begin{myLemma1}{}{}
\lipsum*[1]
\end{myLemma1}

\end{document}

enter image description here

Related Question