Change Tcolorbox title rule color and thickness on the left and right side of the title box

rulestcolorbox

I want to have two distinct styles for my tcolorbox titles as illustrated here:

enter image description here

These are coded in My Title Style Default and My Title Style Special, but use an entire tcolorbox (not just the title). The special style has three distinct changes:

  1. The rule color around all four sides of the title changes. The rule around the other three sides (west, south and east) of the body text should not change.
  2. The left and right rules are thicker to draw attention that these are different.
  3. A few characters xxx are placed on the left hand rule.

So far I am only able to obtain part of requirement 2 and draw the bottom portion of the rule for the special box:

enter image description here

These are coded in My Style Default and My Style Special.

Questions:

  • Main: What changes should I make to the My Style Special to obtain the desired title style for the tcolorbox. Of the three requirements, 2 and 3 are more important, so willing to accept and answer without 1.

  • Bonus: Is there a better way for me to place the xxx text? I had to manually tweak the coordinates

Code:

\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}

Best Answer

Not exactly what you wanted but similar.

\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}

enter image description here

Related Question