问题是如何在 tcolorbox 中将标题放置在框的左下角/右下角。我想创建类似下图的东西。这里的重点是标题“我的图片框”位于框的底部。
答案1
使用attach boxed title to bottom center
键(以及minipage boxed title*
补偿不同的宽度)您可以轻松实现您想要的:
代码:
\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}
答案2
tcolorbox
提供许多放置标题的位置,请参阅手册第 112 页第 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}
但是,这些预定义样式不符合问题中提供的图片中的规格。为此,您可以使用灵活性tcolorbox
并使用节点。
\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}