5

Until now, I have used mdframed to produced nice framed boxes. I recently discovered tcolorbox, and found that it has several advantages over mdframed. In my actual and future work I would prefer tcolorbox. Nevertheless, one nice thing in mdframed is the \mdfsubtitle. You can divide a framed box into several "sections" with nice formatted titles, as seen in the picture (copied from the mdframed documentation):

example of an framed box with one subtitle; copied from the documentation

My Question: is there a (more or less) simple way of having such subtitles with tcolorbox?

1
  • Welcome to TeX.SE. You can have exactly one upper and one lower box with the tcolorbox command. However, you can nest boxes
    – user31729
    Apr 23, 2014 at 14:52

2 Answers 2

5

As far as I know there are no direct options like in mdframed but you can easily build your subtitle box.

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\newtcolorbox{mybox}{
   enhanced,
   bottom=1pt,
   top=1pt,
   arc=0pt,
   boxrule=.4pt,
   before=\vskip6pt,
   colback=yellow!70!white,
   oversize
}

\begin{document}
  \begin{tcolorbox}[title=Theorem,colbacktitle=yellow!70!white,colback=blue!20!white,coltitle=black]
     Some text ...
  \begin{mybox}
     test
  \end{mybox}
     some text
  \end{tcolorbox}
\end{document}

enter image description here

The idea is to create a custom tcolorbox (mybox in the mwe) that you'll use as a subtitle box. Every time you want a subtitle just nest a mybox into your main box and you're set. The inner boxes use the oversize key which removes the margin of the outer box giving the desired effect.

2

tcolorbox now has a \tcbsubtitle option:

enter image description here

Code:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\newtcolorbox{mybox}{
   enhanced,
   bottom=1pt,
   top=1pt,
   arc=0pt,
   boxrule=.4pt,
   before=\vskip6pt,
   colback=yellow!70!white,
   oversize
}

\begin{document}
  \begin{tcolorbox}[title=Theorem,colbacktitle=yellow!70!white,colback=blue!20!white,coltitle=black]
     Some text ...
     \tcbsubtitle{test}
     some text
  \end{tcolorbox}
\end{document}
1
  • I discovered this feature recently. It's nice to have subtitles directly implemented into the package.
    – Michael P
    May 17, 2018 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .