I want to create a nice box like the one in the image below. I tried to use this link: title style in tcolorbox
[Tex/LaTex] How to create a nice box
tablestcolorbox
Related Solutions
Using the attach boxed title to bottom center
key (along with minipage boxed title*
to compensate the different width) you can easily achieve what you want:
The code:
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox{mybox}[2][]{
enhanced,
arc=0pt,
outer arc=0pt,
minipage boxed title*=-1.95em,
title=#2,
fonttitle=\sffamily,
watermark opacity=0.25,
watermark stretch=1.00,
watermark graphics=lichtspiel.jpg,
attach boxed title to bottom center={yshift=2pt},
boxed title style={
enhanced,
watermark opacity=0.75,
watermark stretch=1.00,
watermark graphics=lichtspiel.jpg,
arc=0pt,
outer arc=0pt,
},
#1
}
\begin{document}
\begin{mybox}{This is the title}
\lipsum[4]
\end{mybox}
\end{document}
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:
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:
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:
Best Answer
Some thing like this:
You can use the feature-rich
tcolorbox
package with your own style. You should add the\tcbuselibrary{skins}
library to be able to add customTikZ
overlay
s using the\tcbset{examplebox/.style={...}}
. You will also need a\newcounter
to automatically number your example solutions. This is achieved by:and in the options for
tcolorbox
, addstep=mycounter,label=<...>
for cross referencing. Therefore, In your style definition, put the\themycounter
command in place of the example number.