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

1
  • "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 ( meta.tex.stackexchange.com/questions/228/…), and it'll be a lot easier for people to help you. Jun 13, 2015 at 17:01

1 Answer 1

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

12
  • 1
    @VoDucHoangVu Please see my updated answer. Now you can provide an optional title using an optional argument for the environments. Jun 13, 2015 at 17:40
  • 1
    @Very23 Feel free to open a follow-up question. Jun 30, 2015 at 0: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 9, 2015 at 15:03
  • 3
    @GonzaloMedina As always, very nice solution, and good job on being so patient and helpful. :) +1 Jul 9, 2015 at 16:21
  • 1
    @DanielW.Farlow Thank you for your kind words :) Jul 9, 2015 at 16:23

You must log in to answer this question.

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