2

I'm using the tcolorbox to set a couple of theorems in my thesis. The problem is, that the longest "name" (What they call description in the Documentation.) is just too long for one line.

Here is a MWE (this is the somewhat customized style I would like to use):

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

\definecolor{theoremgray}{rgb}{0.93, 0.93, 0.93}
\newtcbtheorem{theorem}{Theorem}%
{
    enhanced, 
    frame empty, breakable,
    colframe=black, coltitle=black,
    fonttitle=\bfseries , colbacktitle=white,
    fontupper=\slshape, colback=theoremgray,
    borderline={0.5mm}{0mm}{theoremgray},
    attach boxed title to top left,,
    boxed title style={boxrule=0.5mm, rounded corners},
    boxed title size={copy},
    minipage boxed title
}{theo}

\begin{document}

\begin{theorem}{This is a slightly too long title that just causes a break}{test1}
Some text in my theorem.
\end{theorem}
\end{document}

enter image description here

What I would like to do is to set it up such, that only "Theorem 1:" is written in the first line of the title box and the name (description) in a second line, however, it should start directly under "Theorem 1:". That way, the whole thing would fit in one line. I checked the documentation of the tcolorbox package and tried a couple of things, like using separator sign={\newline} (which does not do anything for me) or description formatter=\newline which starts the description in a new line, but with wrong alignment.

Is there a way to do this?

1 Answer 1

1

Update:

With tcolorbox v4.50 (2021/05/21) or newer, this can be achieved with theorem hanging indent=0pt, a newly added key suggested in my feature requestion tcolorbox#126.

The following example has been updated to be compatible with tcolorbox both older and not-older than v4.50.

Original answer:

This patches the internal macro \tcb@theo@title used to typeset the title of a tcb theorem, and deletes the hanging indent part.

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{many}
\usepackage{xpatch}

\definecolor{theoremgray}{rgb}{0.93, 0.93, 0.93}

\newtcbtheorem{theorem}{Theorem}%
{
    enhanced, 
    frame empty, breakable,
    colframe=black, coltitle=black,
    fonttitle=\bfseries , colbacktitle=white,
    fontupper=\slshape, colback=theoremgray,
    borderline={0.5mm}{0mm}{theoremgray},
    attach boxed title to top left,,
    boxed title style={boxrule=0.5mm, rounded corners},
    boxed title size={copy},
    minipage boxed title,
    separator sign={},
    description formatter=\newline,
    % use pgfkeys handler `/.try` to keep backward compatibility 
    theorem hanging indent/.try=0pt,
}{theo}


\makeatletter
% for tcolorbox before v4.50 (2021/05/21), patch \tcb@theo@title
% usage: title={\tcb@theo@title{Theorem}{\thetcbcounter}{<description>}}
\IfPackageAtLeastTF{tcolorbox}{2021/05/21}{
}{
  \xpatchcmd\tcb@theo@title
    {\hangindent\wd\z@\hangafter=1}
    {}
    {}{\fail}
}
\makeatother

\begin{document}

\begin{theorem}{This is a slightly too long title that just causes a break}{test1}
  Some text in my theorem.
\end{theorem}
\end{document}

enter image description here

3
  • Thank you! That is exactly what I was looking for.
    – Rutzky
    Commented Oct 9, 2020 at 18:35
  • @muzimuzhi Z: Unfortunately the code patch shown in this solution doesn't work with updated packages xpatch (2020/03/25 v0.3a) and tclorborx (2021/06/14 version 4.51). I used this solution for quite a long time.
    – JardaFait
    Commented Jul 5, 2021 at 7:22
  • @JardaFait See the updated answer. Commented Jul 5, 2021 at 18:03

You must log in to answer this question.

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