更改标题框左右两侧的Tcolorbox标题规则颜色和粗细

更改标题框左右两侧的Tcolorbox标题规则颜色和粗细

我想让我的 tcolorbox 有两种不同的风格标题如图所示:

在此处输入图片描述

这些是用My Title Style Default和编码的My Title Style Special,但使用整个tcolorbox(而不仅仅是标题)。特别的风格有三个明显的变化:

  1. 标题四边的规则颜色都会改变。正文其他三边(西、南、东)的规则不应改变。
  2. 左右规则较粗,以突出差异。
  3. 一些字符xxx是按照左手法则放置的。

到目前为止,我只能获得要求 2 的一部分,并绘制规则的底部部分特别的盒子:

在此处输入图片描述

My Style Default这些在和中编码My Style Special

问题:

  • 主要的:我应该对 做哪些修改才能My Style Special获得 所需的标题样式tcolorbox。三项要求中,2 和 3 更重要,因此愿意接受并回答,无需 1。

  • 奖金:有没有更好的方法来放置文本xxx?我不得不手动调整坐标

代码:

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

\tcbset{My Title Style Default/.style={
    boxsep=0pt,
    top=4pt,%       
    bottom=1pt,%
    left=5pt,%      left skip
    right=5pt,%     right skip
    boxrule=0.5pt,
    fontupper=\bfseries\color{black},
}}
\tcbset{My Title Style Special/.style={
    My Title Style Default,
    left=1pt,%      adjusted to allow for larger leftrule
    right=1pt,%     adjusted to allow for larger rightrule
    leftrule=4pt,
    rightrule=4pt,
    colframe=red,
    %% ---------------------------------------------------------------
    %% https://tex.stackexchange.com/questions/582034/
    %%         text-along-all-the-four-borders-of-a-tcolorbox
    enhanced,
    overlay={%
        \node[draw=none, fill=none, rotate=90, anchor=north] 
            %% Must be a better way to position this.
            at ([shift={(-2.50pt,0.0pt)}]frame.west) 
            {\scalebox{0.40}{\textcolor{white}{xxx}}};
    },
    %% ---------------------------------------------------------------
}}

\tcbset{My Style Default/.style={
    boxsep=0pt,
    top=4pt,%       Space at top
    bottom=1pt,%    Space at bottom
    left=5pt,%      left skip
    right=5pt,%     right skip
    boxrule=0.5pt,
    colbacktitle=white,
    fonttitle=\bfseries\color{black},
    toptitle=1mm,
    bottomtitle=1mm,
}}

\tcbset{My Style Special/.style={%  What modifications are needed here?
    My Style Default,
    enhanced,
    titlerule=0.5pt,
    titlerule style=red,
}}

\begin{document}
\noindent
Would like two styles of title:
\begin{tcolorbox}[My Title Style Default]
    1. Default Title Style 
\end{tcolorbox}
\begin{tcolorbox}[My Title Style Special]
    2. Special Title Style 
\end{tcolorbox}

\medskip\par\noindent
Want the titles to look like above:

\begin{tcolorbox}[
    My Style Default,
    title={1. Default Title},
]
    The title in this boxe matches the desired default title.
\end{tcolorbox}

\begin{tcolorbox}[
    My Style Special,
    title={2. Special Title},
]
    Desire to match the "Special title" style for this box???
\end{tcolorbox}
\end{document}

答案1

不完全是您想要的,但类似。

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

\tcbset{My Title Style Default/.style={
    boxsep=0pt,
    top=4pt,%       
    bottom=1pt,%
    left=5pt,%      left skip
    right=5pt,%     right skip
    boxrule=0.5pt,
    fontupper=\bfseries\color{black},
}}
\tcbset{My Title Style Special/.style={
    My Title Style Default,
    left=1pt,%      adjusted to allow for larger leftrule
    right=1pt,%     adjusted to allow for larger rightrule
    leftrule=4pt,
    rightrule=4pt,
    colframe=red,
    %% ---------------------------------------------------------------
    %% https://tex.stackexchange.com/questions/582034/
    %%         text-along-all-the-four-borders-of-a-tcolorbox
    enhanced,
    overlay={%
        \node[draw=none, fill=none, rotate=90, anchor=north] 
            %% Must be a better way to position this.
            at ([shift={(-2.50pt,0.0pt)}]frame.west) 
            {\scalebox{0.40}{\textcolor{white}{xxx}}};
    },
    %% ---------------------------------------------------------------
}}

\tcbset{My Style Default/.style={
    boxsep=0pt,
    top=4pt,%       Space at top
    bottom=1pt,%    Space at bottom
    left=5pt,%      left skip
    right=5pt,%     right skip
    boxrule=0.5pt,
    colbacktitle=white,
    fonttitle=\bfseries\color{black},
    toptitle=1mm,
    bottomtitle=1mm,
}}

\tcbset{
    My Style Special/.style={%  What modifications are needed here?
    My Style Default,
    enhanced,
    attach boxed title to top,
    boxed title style={colframe=red, 
        overlay={%
            \begin{tcbclipinterior}
                \draw[line width=3mm, red](frame.north west)--(frame.south west);
                \draw[line width=3mm, red](frame.north east)--(frame.south east);
            \end{tcbclipinterior},
            \node[rotate=90, anchor=north, text=white, inner ysep=1pt] at (frame.west) {\scalebox{0.4}{xxx}};
    }},
}
}

\begin{document}
\noindent
Would like two styles of title:
\begin{tcolorbox}[My Title Style Default]
    1. Default Title Style 
\end{tcolorbox}
\begin{tcolorbox}[My Title Style Special]
    2. Special Title Style 
\end{tcolorbox}

\medskip\par\noindent
Want the titles to look like above:

\begin{tcolorbox}[
    My Style Default,
    title={1. Default Title},
]
    The title in this boxe matches the desired default title.
\end{tcolorbox}

\begin{tcolorbox}[
    My Style Special,
    title={2. Special Title},
]
    Desire to match the "Special title" style for this box???
\end{tcolorbox}
\end{document}

在此处输入图片描述

相关内容