tcolorbox – Setting Default Text in Tcolorbox Body in LaTeX

boxesenvironmentstcolorbox

I'd like to define a tcolorbox environment, e.g.,

\newtcolorbox{mybox}{
enhanced,
boxrule=0pt,frame hidden,
borderline west={3pt}{0pt}{Peach},
colback=Peach!5,
sharp corners
}

But I would like for each box of this kind to begin with a certain keyword, e.g., "Example" – not as a title, just as a part of the body. Is there a way to build this in to the box definition?

Thanks.

Best Answer

As an alternative to my comment, it's also possible to use attach title to upper which includes the title in upper part. In this case, the font and color can be selected with fonttitle or coltitle options.

\documentclass[dvipsnames]{article}
\usepackage[most]{tcolorbox}

\newtcolorbox{mybox}[1][]{
enhanced,
boxrule=0pt,frame hidden,
borderline west={3pt}{0pt}{Peach},
colback=Peach!5,
title=Example,
coltitle=Peach,
attach title to upper={\ },
fonttitle=\bfseries,
sharp corners,
#1
}

\begin{document}
\begin{mybox}
This is an example
\end{mybox}

\begin{mybox}[coltitle=RubineRed, title=Question]
This is a question
\end{mybox}

\end{document}

enter image description here