[Tex/LaTex] Tcolorbox with horizontally separated title and subtitle

tcolorbox

I want to make a tcolorbox that looks roughly like this

-----------------------------------------------------------------------------------
            |          Subtitle (If the subtitle is too long, like it is here, 
TITLE       |          then it should wrap like this, and the title on the left
            |          hand side should be centered relative to the subtitle)
-----------------------------------------------------------------------------------
Here is the content of the tcolorbox.
-----------------------------------------------------------------------------------

The lines should be solid and connected, and the vertical alignment should be as described above. It should be possible to specify the distance from the left margin to the horizontal separator, and from the horizontal separator to the block of subtitle text (this will be used for all tcolorboxes, which may have titles of different lengths. It should be possible to independently specify the fonts used for the title and subtitle.

Here is a minimal example:

\documentclass{report}
\usepackage{tcolorbox}

\newlength{\normalparindent}
\AtBeginDocument{\setlength{\normalparindent}{\parindent}}
\tcbset{before upper={\setlength{\parindent}{\normalparindent}}}

\tcbuselibrary{skins,raster,breakable}
\tcbset{
    enhanced,
    frame hidden,interior hidden,
    sharp corners,
    boxrule=0pt,
    left=-0.1cm,right=-0.1cm,top=0.20cm,bottom=0.35cm,
    toptitle=0.35cm+1pt,
    bottomtitle=0.00cm+1pt,
    colframe=white,colback=white,coltitle=black,
    bottomrule=1pt,
    borderline north={1pt}{0pt}{black},
    borderline south={1pt}{0pt}{black},
    fonttitle=\bfseries,fontupper=\normalsize,
    before skip=0.375cm+2pt,after skip=0.475cm+2pt
}

\begin{document}

\begin{tcolorbox}[title=TITLE]
\noindent Content.
\end{tcolorbox}

\end{document}

Best Answer

Something like that?

enter image description here

In my example code, I made a new environment mybox which takes tcolorbox options as optional argument, then the title and subtitle text as normal arguments.

The new length settings are done by

  my rule=1pt,
  left to separator=3cm,
  separator to subtitle=1cm,

where my rule stores the rule width and the two other options store the distances to the vertical line as you requested.

\documentclass{report}
\usepackage{tcolorbox,lipsum}
\tcbuselibrary{skins,raster,breakable}

\newlength{\normalparindent}
\AtBeginDocument{\setlength{\normalparindent}{\parindent}}
\tcbset{before upper={\setlength{\parindent}{\normalparindent}}}

\tcbset{
  my rule/.store in=\myrule,
  left to separator/.store in=\mylefttoseparator,
  separator to subtitle/.store in=\myseparatortosubtitle,
}

\newtcolorbox{mybox}[3][]{%
  my rule=1pt,
  left to separator=3cm,
  separator to subtitle=1cm,
  enhanced,
  frame hidden,interior hidden,
  sharp corners,
  boxrule=\myrule,boxsep=0pt,
  left=0pt,right=0pt,top=0.35cm,bottom=0.35cm,
  toptitle=0.35cm,bottomtitle=0.35cm,
  colframe=black,colback=white,coltitle=black,
  borderline north={\myrule}{0pt}{black},
  borderline south={\myrule}{0pt}{black},
  fonttitle=\bfseries,fontupper=\normalsize,
  before skip=0.375cm+2pt,after skip=0.475cm+2pt,
  lefttitle=\mylefttoseparator+\myrule+\myseparatortosubtitle,
  title={\raggedright\mbox{}#3},
  underlay unbroken and first={
    \node[right,inner sep=0pt,outer sep=0pt,
      font=\large\bfseries,% <-- title font
      text width=\mylefttoseparator-5mm] at (title.west) {#2};
    \draw[tcbcol@frame,line width=\myrule]
      ([xshift=-\myrule,yshift=-\myrule/2]title.south west)--([xshift=\myrule,yshift=-\myrule/2]title.south east)
      ([xshift=\mylefttoseparator+\myrule/2]title.south west)--([xshift=\mylefttoseparator+\myrule/2]title.north west);
  },
  #1,
}


\begin{document}

\begin{mybox}{TITLE}{SUBTITLE}
\noindent\lipsum[2]
\end{mybox}

\begin{mybox}{TITLE}{Subtitle (If the subtitle is too long, like it is here,
     then it should wrap like this, and the title on the left
     hand side should be centered relative to the subtitle)}
\noindent\lipsum[3]
\end{mybox}

\end{document}
Related Question