10 在title里用tcbox会什么会换行

发布于 2024-07-27 21:14:26

请问为什么把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}

查看更多

关注者
0
被浏览
198
1 个回答
o(∩_∩)o
o(∩_∩)o 2024-07-27
这家伙很懒,什么也没写!

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}

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览