The question is how to place a title in the tcolorbox to the bottom left/right of the box. I want to create something like the following picture. The main point here is the caption "My picture box" being in the bottom of the box.
2 Answers
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}
tcolorbox
offers many positions for placing title, see manual page 112,section 8.2.
\documentclass{article}
\usepackage[many]{tcolorbox}
\begin{document}
\begin{tcolorbox}[enhanced,minipage boxed title,enhanced,title=My title comes here at the bottom,
attach boxed title to bottom left=
{xshift=0mm,yshift=1mm},
boxed title style={size=small,colback=blue},width=5in]
This is a \textbf{tcolorbox}.
\end{tcolorbox}
\end{document}
However, these predefined styles do not meet your specifications in the provided picture in the question. For this you may use the flexibility of tcolorbox
and use a node.
\documentclass{article}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\makeatletter
\newtcolorbox{mybox}[2][]{enhanced jigsaw,
boxsep=0pt,bottom=3mm,left=3mm,right=3mm,top=3mm,boxrule=1pt,colframe=red,arc=0pt,
overlay={%
\node[anchor=north,text width=\tcb@width-4\pgflinewidth-6mm,fill=olive,inner xsep=3mm]
(a) at ([yshift=2mm]frame.south) {#2};
\draw[red,line width=1pt] (a.north west) -- (a.south west) -| (a.north east);
},
#1}
\makeatother
\begin{document}
\begin{mybox}{My title My title My title My title My title My title My title My title My title}
\lipsum[2]
\end{mybox}
\end{document}