1

I have some tcbtheorems that are usually unnumbered but I want to have the flexibility to use them numbered as well.

Here is a minimal example:

\documentclass{article}

\usepackage[most]{tcolorbox}
\usepackage{multicol}

\tcbset{
  detach title,
  fonttitle=\bfseries,
  coltitle=black,
  before upper={\tcbtitle},
  terminator sign={.},
}

\newtcbtheorem[]{myproof1}{Proof}{ colframe=gray }{}
\newtcbtheorem[]{myproof2}{Proof}{ colframe=red, before upper={\tcbtitle~} }{}
\newtcbtheorem[]{myproof3}{Proof}{ colframe=blue, terminator sign={.~} }{}

\begin{document}

\begin{multicols}{2}
  
\begin{myproof1*}{}{}
  This is a proof.
\end{myproof1*}

\begin{myproof2*}{}{}
  This is a proof.
\end{myproof2*}

\begin{myproof3*}{}{}
  This is a proof.
\end{myproof3*}

\begin{myproof1}{}{}
  This is a proof.
\end{myproof1}

\begin{myproof2}{}{}
This is a proof.
\end{myproof2}

\begin{myproof3}{}{}
  This is a proof.
\end{myproof3}

\end{multicols}

\end{document}

PDF output of my minimal example

The gray box is how I normally have things set up and it works perfectly fine until I decide to use it numbered. There should be a space between the number and the content of my box.

I tried to fix this behaviour by adding a tilde after the title (red box) or by adding a tilde after the terminator sign (blue box). Both work as expected, but now there is an extra whitespace in the unnumbered boxes.

I would like to have a single tcbtheorem that behaves like so: enter image description here

2
  • I don't know why but before upper*={\tcbtitle} seems to work. Jan 7, 2022 at 23:18
  • @muzimuzhiZ It does! Thank you very much.
    – gyha4
    Jan 10, 2022 at 11:39

1 Answer 1

1

While the un-starred theorem environments defined by \newtcbtheorem takes one optional argument and two mandatory arguments, the starred version takes one optional argument and only one mandatory argument.

Therefore with \newtcbtheorem[]{myproof1}{Proof}{ colframe=gray }{}, one should use

  • \begin{myproof1}[<options>]{<thm name>}{<label>} ... \end{myproof1}
  • \begin{myproof1*}[<options>]{<thm name>} ... \end{myproof1*}

In OP's example, the second empty {} added to starred envs cancels the effect of \ignorespace which is automatically inserted when before upper={...} is used, so results in inconsistent spaces.

That is, in using

\begin{myproof1*}{}{}
  This is a proof
\end{myproof1*}

The upper part starts from the second {} hence becomes

\tcbtitle\ignorespaces{}<space>This is a proof
                        % this <space>, coming from the newline character, is not ignored

While with the right usage

\begin{myproof1*}{}
  This is a proof.
\end{myproof1*}

the upper part is

\tcbtitle\ignorespaces<space>This is a proof
                      % this <space> is ignored by \ignorespaces

Removing the extra pair of braces, you're served by either before upper={\tcbtitle~} or terminator sign={.~}.

\documentclass{article}

\usepackage[most]{tcolorbox}
\usepackage{multicol}

\tcbset{
  detach title,
  fonttitle=\bfseries,
  coltitle=black,
  before upper={\tcbtitle},
  terminator sign={.},
}

\newtcbtheorem[]{myproof1}{Proof}{ colframe=gray }{}
\newtcbtheorem[]{myproof2}{Proof}{ colframe=red, before upper={\tcbtitle~} }{}
\newtcbtheorem[]{myproof3}{Proof}{ colframe=blue, terminator sign={.~} }{}

\begin{document}

\begin{multicols}{2}
  
\begin{myproof1*}{}%{}
  This is a proof.
\end{myproof1*}

\begin{myproof2*}{}%{}
  This is a proof.
\end{myproof2*}

\begin{myproof3*}{}%{}
  This is a proof.
\end{myproof3*}

  \begin{myproof1}{}{}
  This is a proof.
\end{myproof1}

\begin{myproof2}{}{}
This is a proof.
\end{myproof2}

\begin{myproof3}{}{}
  This is a proof.
\end{myproof3}

\end{multicols}

\end{document}

enter image description here

You must log in to answer this question.

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