Ethebeth
Ethebeth
这家伙很懒,什么也没写!

注册于 1年前

回答
2
文章
0
关注者
0

由于找不到编辑原问题的位置,现将最后我使用的【可行的】代码附在此处。

  \newtcbtheorem
    [number within=chapter, Crefname={Definition}{Definitions}]
    {definition}
    {Definition}
    {
        fonttitle={\bfseries\fontsize{14}{14}\selectfont\color{colorDefinition}},
        opacityback=0,
        left=.75em,
        right=.75em,
        top=1.5ex,
        bottom=1.2ex,
        before skip=10pt plus 1pt minus 1pt,
        after skip =14pt plus 1pt minus 1pt,
        arc=0pt,
        enhanced,
        breakable,
        boxrule=0pt,
        frame hidden,
        borderline south={1pt}{0mm}{colorDefinition},
        borderline west ={1pt}{0mm}{colorDefinition},
        borderline east ={1pt}{0mm}{colorDefinition},
        attach boxed title to top left={
            yshift=-8pt,
            yshifttext=-1mm,
            xshift=2em 
        },
        overlay unbroken and first ={
            \draw [line width=1pt, color=colorDefinition]
              ([yshift=-2pt]title.west) -- ++(-2em,0pt);
            \draw [line width=1pt, color=colorDefinition]
              ([yshift=-2pt]title.east) -- +(2em,0pt);
        },
        boxed title style={
            frame style   ={fill=none},
            interior style={fill=none},
            left=.25em,
            right=.25em,
            top=.25ex,
            bottom=.25ex,
            height=20pt
        }
    }
    {def}

这里使用了overlay unbroken and first来处理顶部横线的绘制:unbroken在框未分页(由于被设置为unbreakable或者是确实没有分页)的时候绘制,first在框分页时绘制于第一页。

目前我使用的如下:

  \newtcbtheorem
    [number within=chapter, Crefname={Definition}{Definitions}]
    {definition}
    {Definition}
    {
        fonttitle={\bfseries\fontsize{14}{14}\selectfont\color{colorDefinition}},
        opacityback=0,
        left=.75em,
        right=.75em,
        top=1.5ex,
        bottom=1.2ex,
        before skip=10pt plus 1pt minus 1pt,
        after skip =14pt plus 1pt minus 1pt,
        arc=0pt,
        enhanced,
        breakable,
        boxrule=0pt,
        frame hidden,
        borderline south={1pt}{0mm}{colorDefinition},
        borderline west ={1pt}{0mm}{colorDefinition},
        borderline east ={1pt}{0mm}{colorDefinition},
        attach boxed title to top left={
            yshift=-8pt,
            yshifttext=-1mm,
            xshift=2em 
        },
        overlay ={
          \begin{tcbclipinterior}
            \draw [line width=1pt, color=colorDefinition]
              ([yshift=-2.5pt]title.west) -- ++(-2em,0pt);
            \draw [line width=1pt, color=colorDefinition]
              ([yshift=-2.5pt]title.east) -- +(2em,0pt);
          \end{tcbclipinterior}
        },
        boxed title style={
            frame style   ={fill=none},
            interior style={fill=none},
            left=.25em,
            right=.25em,
            top=.25ex,
            bottom=.25ex,
            height=20pt
        }
    }
    {def}

改动之处包括增加 boxed title style 的 height 属性,保证添加了标题(比如 Definition 添加标题 poutine)之后不会影响 box 的位置(从而影响画的横线)。
使用 overlay 而非 frame code app,这样在跨页时仍然能正确绘制。

发布
问题