我有一个类似于以下的文档:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}
\newtcolorbox{definition}[2][]{
arc=5mm,
lower separated=false,
fonttitle=\bfseries,
colbacktitle=green!10,
coltitle=green!50!black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
yshift=-3mm},
colframe=green!50!black,
colback=green!10,
title=#2}
\begin{document}
\begin{definition}{Assume we have a title that is waaaaaaay too long to fit in a single line and therefore requires a line break}
\blindtext
\end{definition}
\end{document}
答案1
作为一种解决方法,您可以将标题放在\parbox
相应大小中:
\documentclass{article}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}
\newtcolorbox{definition}[2][]{
arc=5mm,
lower separated=false,
fonttitle=\bfseries,
colbacktitle=green!10,
coltitle=green!50!black,
enhanced,
attach boxed title to top left={xshift=0.5cm,
yshift=-3mm},
colframe=green!50!black,
colback=green!10,
title=#2}
\begin{document}
\begin{definition}{\parbox{10.45cm}{Assume we have a title that is waaaaaaay too long to fit in a single line and therefore requires a line break}}
\blindtext
\end{definition}
\end{document}
答案2
tcolorbox
为长标题定义了几种解决方案:minipage boxed title
,,varwidth boxed title
。tikznode boxed title
以下是第一个示例:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}
\newtcolorbox{definition}[2][]{
arc=5mm,
lower separated=false,
fonttitle=\bfseries,
colbacktitle=green!10,
coltitle=green!50!black,
enhanced,
minipage boxed title*=-3cm,
attach boxed title to top left={xshift=.5cm, yshift*=-\tcboxedtitleheight/2},
colframe=green!50!black,
colback=green!10,
title=#2}
\begin{document}
\begin{definition}{Assume we have a title that is waaaaaaay too long to fit in a single line and therefore requires a line break}
\blindtext
\end{definition}
\end{document}