Tcolorbox vertical alignment title changing

tcolorbox

mdframed always creates bad breaks, I tried to solve this and read about people saying it is not supported anymore and that tcolorbox is a better solution. I recreated my theorem boxes with tcolorbox but now I'm facing a text alignment issue: when the title gets too long, the alignment changes. I did a comparison between mdframed with a short title, mdframed with a long title, tcolorbox with a short title and tcolorbox with a long title.

see the gap

Here is my code :

\begin{boiterouge}[\textbf{\textsc{The-rem} -- title some title mdframed}]
This is some random text
\end{boiterouge}

\begin{boiterouge}[\textbf{\textsc{The-rem}}]
This is some random text
\end{boiterouge}

\begin{tcolorbox}[enhanced,title=\textbf{\textsc{The-rem} -- title some title tcolorbox} ,colframe=rougestyle,coltitle=rougestyle,colback=white,
attach boxed title to top left=
{yshift=-3mm,xshift=4mm},left=2.5mm,top=2mm,bottom=0.5mm,
boxed title style={opacityback=0,colframe=white,size=fbox,arc=0mm},sharp corners]
This is some random text
\end{tcolorbox}

\begin{tcolorbox}[enhanced,title=\textbf{\textsc{The-rem}} ,colframe=rougestyle,coltitle=rougestyle,colback=white,
attach boxed title to top left=
{yshift=-2.5mm,xshift=4mm},
boxed title style={opacityback=0,colframe=white,size=fbox,arc=0mm},sharp corners]
This is some random text
\end{tcolorbox}

Best Answer

My comment is no good! If there is a letter with a depth (g, j, p, q) in the title, the alignment changes

enter image description here

With \vphantom{p}, a letter with a depth, the alignment will be the same. Surely there is better to do.

    \documentclass{article}
    \usepackage{tcolorbox}
    \tcbuselibrary{skins}
    \begin{document}
    \tcbset{%
    enhanced,
    colframe=red,
    coltitle=red,
    colback=yellow,
    boxed title style={opacityback=0,colframe=white,size=fbox,arc=0mm},
    attach boxed title to top left={yshift=-\tcboxedtitleheight/2,xshift=4mm}
    }%

    \begin{tcolorbox}[title=\textbf{\textsc{The-rem}}]
    Without vphantom{bp}
    \end{tcolorbox}
    \begin{tcolorbox}[title=\textbf{\textsc{The-remg}}]
    Without vphantom{bp}
        \end{tcolorbox}
    \begin{tcolorbox}[title=\textbf{\textsc{The-rem} -- title some title tcolorbox}]
        Without vphantom{bp}
    \end{tcolorbox}
    \begin{tcolorbox}[title=\textbf{\vphantom{bp}\textsc{The-rem} -- title some title tcolorbox}]
        With vphantom{bp}
    \end{tcolorbox}
    \end{document}
Related Question