对齐 tcolorboxes 的标题

对齐 tcolorboxes 的标题

这是我当前的代码:

\documentclass{minimal}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}

\tcbset{roundedbox/.style={
        breakable,  % allows linebreaks
        enhanced,
        outer arc=5pt,
        arc=5pt,
        colframe=Green,
        colback=Green!10,
        boxed title style={
            colback=Green,
            outer arc=0pt,
            arc=0pt,
            top=3pt,
            bottom=3pt,
        },
        fonttitle=\sffamily
    }
}

\newtcolorbox[auto counter]{question_rounded}[2][]{
    roundedbox,
    title=Question~\thetcbcounter: {#1},
    colback = white,
    label=#2
}

\begin{document}
    \begin{question_rounded}[Here comes a possibly long title, which stretches over several lines and of which the next line should be directly east of ``Question 1:'']{label}
        Here comes the answer.
    \end{question_rounded}
\end{document}

输出:在此处输入图片描述

我怎样才能对齐问题,使得每一行新行都位于“问题 xy:”部分的东边?

答案1

使用\parbox作为标题。

b

\documentclass{minimal}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}

\tcbset{roundedbox/.style={
        breakable,  % allows linebreaks
        enhanced,
        outer arc=5pt,
        arc=5pt,
        colframe=Green,
        colback=Green!10,
        boxed title style={
            colback=Green,
            outer arc=0pt,
            arc=0pt,
            top=3pt,
            bottom=3pt,
        },
        fonttitle=\sffamily
    }
}

\usepackage{calc} % added <<<<<<<<
\newlength{\questionlabel}

\newtcolorbox[auto counter]{question_rounded}[2][]{
    roundedbox,
    title=Question~\thetcbcounter:\enspace{\settowidth{\questionlabel}{\widthof{Question~\thetcbcounter:\enspace}}\parbox{\linewidth-\questionlabel}{#1}},
    colback = white,
    label=#2
}

\begin{document}
            
    \begin{question_rounded}[Here comes a possibly long title, which stretches over several lines and of which the next line should be directly east of ``Question 1:'']{label}
        Here comes the answer.
    \end{question_rounded}  

\end{document}

相关内容