TransWikia.com

tcolorbox custom title box style

TeX - LaTeX Asked on March 20, 2021

could anyone write the code to obtain a similar shape for the title of the box? the awkwardly drew line is to show a shape with no angular points. The title box must look like a rounded box inside the big box, slightly pushed upward. The big box is kind of rubber protected all around. They both must look like one piece only. The background color of the box could be white. A little bit like the title style of the bottom example, p. 165 of the tcolorbox manual 4.30.
enter image description here

Update
here is another example. Actually filling colours are often used to hide things.

enter image description here

One Answer

More or less:

documentclass{article}
usepackage[most]{tcolorbox}
usepackage{varwidth}
usepackage{lipsum}

newtcolorbox{mybox}[2][]{enhanced, interior hidden,
colframe=cyan!30, colback=cyan!30, coltitle=blue!70!black,
fonttitle=bfseriessffamily,
attach boxed title to top left,
boxed title style={empty, boxrule=0.5mm},
varwidth boxed title=0.5linewidth,
underlay boxed title={
path[draw=cyan!30, line width=0.5mm, rounded corners, fill=cyan!30]
([xshift=.25mm]frame.west) |- ([xshift=-2.5mm]title.north east) to[out=0, in=180] ([xshift=7.5mm, yshift=-.25mm]title.south east);  
},
title={#2},#1}
begin{document}

begin{mybox}{My title}
lipsum[2]
end{mybox}

begin{mybox}{A longer title}
lipsum[2]
end{mybox}

end{document}

enter image description here

Update: white background and lower title

documentclass{article}
usepackage[most]{tcolorbox}
usepackage{varwidth}
usepackage{lipsum}

newtcolorbox{mybox}[2][]{empty, 
coltitle=black,
fonttitle=bfseriessffamily,
attach boxed title to top left={yshift=-2.5mm},
boxed title style={empty, size=small, top=1mm, bottom=0pt},
varwidth boxed title=0.5linewidth,
frame code={
path (title.east|-frame.north) coordinate (aux);
path[draw=black, line width=0.5mm, rounded corners]
(frame.west) |- ([xshift=-2.5mm]title.north east) to[out=0, in=180] ([xshift=7.5mm]aux)-|(frame.east)|-(frame.south)-|cycle;  
},
title={#2},#1}
begin{document}

begin{mybox}{My title}
lipsum[2]
end{mybox}

begin{mybox}{A longer title}
lipsum[2]
end{mybox}

end{document}

enter image description here

Answered by Ignasi on March 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP