13

anyone can help me with latex code how to create a box as the following figures? enter image description here

the second box is

enter image description here

I tried to use package{tcolorbox}, but not succeed. I would like to create a box exactly as in figure 1 with that color! I would like to automatically numbering "Assumption SLR. xx" in figure 1 as well as in figure 2 with "Example 1.xxx"

Thanks

Vũ Võ
  • 465
  • "It didn't work" doesn't help anyone help you; what exactly did you try, and what failed? tcolorbox can absolutely do what you want, but you're asking others to do all the work for you, which isn't really fair. Try to construct a minimal working example ( http://meta.tex.stackexchange.com/questions/228/ive-just-been-asked-to-write-a-minimal-example-what-is-that), and it'll be a lot easier for people to help you. – dgoodmaniii Jun 13 '15 at 17:01

1 Answers1

29

Improved version:

\documentclass{article}
\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}

\definecolor{myblue}{RGB}{0,163,243}

\tcbset{mystyle/.style={ breakable, enhanced, outer arc=0pt, arc=0pt, colframe=myblue, colback=myblue!20, attach boxed title to top left, boxed title style={ colback=myblue, outer arc=0pt, arc=0pt, top=3pt, bottom=3pt, }, fonttitle=\sffamily } }

\newtcolorbox[auto counter,number within=section]{example}[1][]{ mystyle, title=Example~\thetcbcounter, overlay unbroken and first={ \path let \p1=(title.north east), \p2=(frame.north east) in node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1] at (title.east) {#1}; } } \newtcolorbox[auto counter]{assumption}[1][]{ mystyle, colback=white, rightrule=0pt, toprule=0pt, title=Assumption SLR.\thetcbcounter, overlay unbroken and first={ \path let \p1=(title.north east), \p2=(frame.north east) in node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1] at (title.east) {#1}; } }

\begin{document}

\section{Test section} \begin{example} test \end{example} \begin{assumption} test \end{assumption} \begin{example}[Optional title] test \end{example} \begin{assumption}[Optional title with some more words for the example so it spans two lines] test \end{assumption}

\end{document}

The result:

enter image description here

First version:

One possibility:

\documentclass{article}
\usepackage[many]{tcolorbox}

\definecolor{myblue}{RGB}{0,163,243}

\tcbset{mystyle/.style={ breakable, enhanced, outer arc=0pt, arc=0pt, colframe=myblue, colback=myblue!20, attach boxed title to top left, boxed title style={ colback=myblue, outer arc=0pt, arc=0pt, }, title=Example~\thetcbcounter, fonttitle=\sffamily } }

\newtcolorbox[auto counter,number within=section]{example}[1][]{ mystyle, title=Example~\thetcbcounter, } \newtcolorbox[auto counter]{assumption}[1][]{ mystyle, title=Assumption SLR.\thetcbcounter, }

\begin{document}

\section{Test section} \begin{example} test \end{example} \begin{assumption} test \end{assumption}

\end{document}

The output:

enter image description here

I used the same style for both examples and assumptions, but if you also want to reproduce the other style, a simple modification will do:

\documentclass{article}
\usepackage[many]{tcolorbox}

\definecolor{myblue}{RGB}{0,163,243}

\tcbset{mystyle/.style={ breakable, enhanced, outer arc=0pt, arc=0pt, colframe=myblue, colback=myblue!20, attach boxed title to top left, boxed title style={ colback=myblue, outer arc=0pt, arc=0pt, }, title=Example~\thetcbcounter, fonttitle=\sffamily } }

\newtcolorbox[auto counter,number within=section]{example}[1][]{ mystyle, title=Example~\thetcbcounter, } \newtcolorbox[auto counter]{assumption}[1][]{ mystyle, colback=white, rightrule=0pt, toprule=0pt, title=Assumption SLR.\thetcbcounter, }

\begin{document}

\section{Test section} \begin{example} test \end{example} \begin{assumption} test \end{assumption}

\end{document}

The output:

enter image description here

Gonzalo Medina
  • 505,128
  • 1
    @VoDucHoangVu Please see my updated answer. Now you can provide an optional title using an optional argument for the environments. – Gonzalo Medina Jun 13 '15 at 17:40
  • @GonzaloMedina your last version really helped me but I need to add one more argument in order to get some of the boxes with the \tcblower and I've tried with the before title option and put the title option into the overlay unbroken and first but nothing worked :( – Very23 Jun 30 '15 at 00:14
  • 1
    @Very23 Feel free to open a follow-up question. – Gonzalo Medina Jun 30 '15 at 00:49
  • 1
    @GonzaloMedina: If I put long title in the example environment as code did above, the title will "over-run" the width of the box. I tried to use break line "//" to break the title. But it not succeed. Can you help to over come this small issue? Thanks – Vũ Võ Jul 09 '15 at 15:03
  • @VoDucHoangVu Sure, I can provide a solution. However, I'd like to know the desired result for titles spanning several lines. How wxactly should the multiline text appear in relation to the box containing "Example #"? I mean, suppose the title is so long it spans three lines. What should happen to the blue box with "Example #"? Should its height be enlarged to acomodate the three lines of the title? If so, should "Example #" be centered with respect to those three lines of the title or should it be top aligned? – Gonzalo Medina Jul 09 '15 at 15:32
  • @GonzaloMedina: In the book I have, the blue box with "Example #" does not expand its height to accommodate with the lines of title. However, you can help me with the two codes: i) one as I mentioned; and ii) one as you suggested if you have time for it. Thanks you so much. – Vũ Võ Jul 09 '15 at 15:49
  • @VoDucHoangVu So, in the book, the title lines get "squeezed" to always fit in the fixed height? It would help me a lot if you could provide me with an image of the desired result. Can you please upload (to Imgur, for example) an image of an example where the title spans more than one page and provide the link here in a comment so I can have a better idea? – Gonzalo Medina Jul 09 '15 at 15:56
  • @VoDucHoangVu Nevermind. Please see my updated answer. Is something like this what you have in mind? – Gonzalo Medina Jul 09 '15 at 16:04
  • @GonzaloMedina: here is link leading to the pic that having title "over-run":[link] https://picasaweb.google.com/115266452676465186059/Ngay09Thang07Nam2015#6169541517426057570 . Here is the link leading to the pic captured in the book with the break title. https://picasaweb.google.com/115266452676465186059/Ngay09Thang07Nam2015#6169541517949338530 – Vũ Võ Jul 09 '15 at 16:14
  • 3
    @GonzaloMedina As always, very nice solution, and good job on being so patient and helpful. :) +1 – Daniel W. Farlow Jul 09 '15 at 16:21
  • 1
    @DanielW.Farlow Thank you for your kind words :) – Gonzalo Medina Jul 09 '15 at 16:23