8

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?
  • 1
    Apparently, you want to have the text Area of the region... right to the framed title box? – user31729 Dec 28 '15 at 12:55
  • @ChristianHupfer yeah, if possible . – Educ Dec 28 '15 at 12:58
  • Difficult, I think, at least using it this way :-( – user31729 Dec 28 '15 at 13:27
  • 1
    @Educ Would something like this do it for you? – Alenanno Dec 28 '15 at 19:27
  • 1
    @Educ Gotcha! :D – Alenanno Dec 28 '15 at 19:32
10

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

  • I have a problem with this solution, if inside myLemma1 I write "something", then add a tasks environment, and write "stuff", the "stuff" has a huge indentation. Like so: i.imgur.com/Zszlyjf.jpg – The Fourth Man Mar 10 '16 at 7:44
7

Warning: Awful hack ahead ;-)

It's difficult to align the running text and the attached title box -- perhaps there are some options in tcolorbox manual, but I did not found it.

Since the attached title box itself is a tcolorbox, most (all?) settings to this can be done the same way like for the outer box.

I've used however a separate \newtcolorbox -- it's not the tcbtheorem any longer, to provide for more flexibility (Using the xparse facilities of tcolorbox would improve this even more)

\documentclass{article}


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


\usepackage[margin=1.5cm]{geometry}

\newtcolorbox[auto counter]{myinternallemma}[2][]{%
  enhanced,
  title={\phantom{Some}},
  detach title,
  attach title to upper={\hskip0.2\textwidth},
  description color=Maroon,  
  top=-5pt,
  colbacktitle=white, coltitle=black,    
  boxed title style={%
    enhanced,arc=0pt,
    bottomtitle=1pt,
    boxrule=1pt,
    coltitle=black,
    lowerbox=ignored,
    size=normal,
    sharp corners,
    width={0.1\textwidth},
    fonttitle={\bfseries},
    title={Question \thetcbcounter},
    attach title to upper={},
    box align=bottom,
  },%
  attach boxed title to top left={%
    yshift=-\tcboxedtitleheight,
  },
  #1
}

\usepackage{blindtext}
\usepackage{pifont}
\usepackage{fancybox}

\begin{document}

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

\end{document}

enter image description here

  • @Educ: ;-) Please consider to accept Ulrike Fischer's solution. Her answer is clearer and easier! – user31729 Dec 28 '15 at 19:10
  • okay as you want :) – Educ Dec 28 '15 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.