[Tex/LaTex] tcolorbox, subtitle style

tcolorbox

I'm working with a new tcolorbox-environment defined by another person that I need to modify a bit, but I'm cluless how to do it. I have been struggling with the manual by Thomas F. Sturm. Here is the code I have until know:

\documentclass[]{article}
\RequirePackage[most]{tcolorbox} 
\RequirePackage{xcolor}

\definecolor{commentgreen}{HTML}{E0E5C1}

\newtcolorbox{commentbox}[2][]{
    frame hidden,
    boxrule=0pt,
    breakable,
    enhanced,
    before skip=8pt plus 1pt,
    toptitle=3mm,
    boxsep=0.25ex,
    left=8pt,
    right=8pt,
    arc=0mm,
    fonttitle=\fontfamily{fosj}\selectfont\scshape\bfseries\color{black},
    fontupper=\fontfamily{lmss}\selectfont,
    title=#2,
    parbox = false,
    colback=commentgreen,
    colframe=commentgreen,
    colbacktitle=commentgreen,
    after={\vspace{5pt plus 1pt}\noindent},
    #1
}

\begin{document}

\begin{commentbox}{Title}
\tcbsubtitle[]{Sub-title}
Main Text is going to be here
\end{commentbox}
\end{document}

enter image description here

I need the subtitle just below of the title (almost as a regular line skip) in a smaller font size with italics instead of bold, and a bigger gap between the subtitle and the main text, like the one between the title and the subtitle.

I gave up on the idea of adding the subtitles specifications to the newtcolorbox definition, so I tried to add the subtitle inside, as shown in the code and then adding \scriptsize{\textit{Subtitle}}, but it's still bold and I found no way to adjust the spaces that I need.

I hope someone can guide me a bit, thanks.

Happy new year.

Best Answer

I suggest to define a separate style for this, say mysubtitle.

(I've changed Arash Esbati's proposition 'slightly')

Since \tcbsubtitle itself is a tcolorbox, it accepts the same options like the outer box.

The most crucial option (in my point of view) is top=0pt (for example) and nobeforeafter for the subtitle.

Since tcbsubtitle is tcbox, fontupper instead of fonttitle has to be used, as well as colback.

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

\definecolor{commentgreen}{HTML}{E0E5C1}

\newtcolorbox{commentbox}[2][]{
    frame hidden,
    boxrule=0pt,
    breakable,
    enhanced,
    before skip=8pt plus 1pt,
    toptitle=3mm,
    boxsep=0.25ex,
    left=8pt,
    right=8pt,
    arc=0mm,
    fonttitle=\fontfamily{fosj}\selectfont\scshape\bfseries\color{black},
    fontupper=\fontfamily{lmss}\selectfont,
    title=#2,
    parbox = false,
    colback=commentgreen,
    colframe=commentgreen,
    colbacktitle=commentgreen,
    after={\vspace{5pt plus 1pt}\noindent},
    #1
}

\tcbset{mysubtitle/.style={subtitle style={fontupper={\fontfamily{fosj}\selectfont\itshape\scriptsize\color{black}},nobeforeafter,top=0pt,colback={commentgreen}},top=0pt}}

\begin{document}

\begin{commentbox}[mysubtitle]{Title}
  \tcbsubtitle{Sub-title}
  Main Text is going to be here
\end{commentbox}
\end{document}

enter image description here

Related Question