tcolorbox 修改

tcolorbox 修改

我有以下代码:

\documentclass{article}
\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}

\definecolor{myblue}{RGB}{0,163,243}

\tcbset{mystyle/.style={
  breakable,
  enhanced,
  outer arc=0pt,
  arc=0pt,
  colframe=myblue,
  colback=myblue!20,
  attach boxed title to top left,
  boxed title style={
    colback=myblue,
    outer arc=0pt,
    arc=0pt,
    top=3pt,
    bottom=3pt,
    },
  fonttitle=\sffamily
  }
}

\newtcolorbox[auto counter]{assumption}[1][]{
  mystyle,
  colback=white,
  rightrule=0pt,
  toprule=0pt,
  title=Assumption SLR.\thetcbcounter,
  overlay unbroken and first={
      \path
        let
        \p1=(title.north east),
        \p2=(frame.north east)
        in
        node[anchor=west,font=\sffamily,color=myblue,text width=\x2-\x1] 
        at (title.east) {#1};
  }
}

\begin{document}

\begin{assumption}
test
\end{assumption}

\end{document}

结果是这样的: 在此处输入图片描述

我想要的是: 在此处输入图片描述

谁能帮我?

答案1

这里有两个重要的attach选项:

attach boxed title to top left={yshift=-\tcboxedtitleheight, yshifttext=-\baselineskip}

即将框向下移动框的高度(\tcboxedtitleheight),并为主框提供额外的间距,以使框标题不与主文本区域重叠yshifttext=-\baselineskip,其中\baselineskip仅仅是一个例子。

\documentclass{article}
\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}

\definecolor{myblue}{RGB}{0,163,243}

\tcbset{mystyle/.style={
  breakable,
  enhanced,
  sharp corners,
  colframe=myblue,
  colback=myblue!20,
  attach boxed title to top left={yshift=-\tcboxedtitleheight, yshifttext=-\baselineskip},
  boxed title style={
    enhanced,
    sharp corners,
    colback=myblue,
    top=2pt,
    bottom=2pt,
    size=small,
    },
  fonttitle=\sffamily
  },
}

\newtcolorbox[auto counter]{assumption}[1][]{
  mystyle,
  colback=white,
  title=Assumption SLR.\thetcbcounter,
}

\begin{document}

\begin{assumption}
test
\end{assumption}

\end{document}

在此处输入图片描述

相关内容