请问为什么把title=例~\theexamplecounter
改成了 title=\myexample{例\theexamplecounter}
之后为换行?请问如何解决这个换行的问题?
\documentclass{ctexart}
\usepackage[most]{tcolorbox}
\usepackage{zhlipsum}
\newtcbox{\myexample}{
enhanced,
left=1pt,
right=1pt,
top=2pt,
bottom=2pt,
boxrule=-1pt,
toprule=1pt,
colback=white,
colframe=cyan,
}
\newcounter{examplecounter}
\setcounter{examplecounter}{1}
\newtcolorbox{example}{
enhanced,
breakable,
colback=white,
colframe=white,
colbacktitle=cyan!10,
coltitle=cyan,
attach title to upper,
% title=例~\theexamplecounter ,
title=\myexample{例\theexamplecounter} ,
before upper=\tcbtitle \;,
}
\begin{document}
\begin{example}
\zhlipsum[12]
\end{example}
\end{document}
mwe.zip
加入on line
\documentclass{ctexart}
\usepackage[most]{tcolorbox}
\usepackage{zhlipsum}
% 定义一个不会换行的命令
\newtcbox{\myexample}{
enhanced,
left=1pt,
right=1pt,
top=2pt,
bottom=2pt,
boxrule=-1pt,
toprule=1pt,
colback=white,
colframe=cyan,
on line, % 确保命令在行内执行,不会导致换行
}
\newcounter{examplecounter}
\setcounter{examplecounter}{1}
\newtcolorbox{example}{
enhanced,
breakable,
colback=white,
colframe=white,
colbacktitle=cyan!10,
coltitle=cyan,
attach title to upper,
title=\myexample{例~\theexamplecounter} ,
before upper=\tcbtitle \;,
}
\begin{document}
\begin{example}
\zhlipsum[12]
\end{example}
\end{document}