0

I would like to simply update my preamble to use tcolorbox for theorems without needing to manually remove the \label{} found after every \begin{theorem} or to replace the optional argument corresponding to the title. That is, I would like my theorem environment to look like

\begin{theorem}[optional title]\label{optional label}
Theorem text.
\end{theorem}

while still using the tcolorbox theorem from the Theorem library. Is there a way this can be done?

Edit: here is an MWE.

\documentclass{article}
\usepackage{amsthm}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[
    auto counter,
    number within=section,
    ]{theorem}{Theorem}{
    colback=gray!25,
    colframe=gray!90!black,
    fonttitle=\bfseries}{thm}

\begin{document} \begin{theorem}{tcb label style}{works} Can cite \ref{thm:works}. \end{theorem}

\begin{theorem}{default label style}{}
    \label{thm:doesntwork}
    Can cite \ref{thm:doesntwork}.
\end{theorem}

\end{document}

which outputs output of \label in tcbtheorem

Additionally, whatever mechanism my text editor uses to autosuggest labels when writing \ref and such does not work with the \begin{theorem}{title}{label} method provided by tcolorbox.

Edit 2: the following works but is not ideal.

\newtheoremstyle{tcb-drop-in-thm}% 〈name〉
                {}% 〈Space above〉1
                {}% 〈Space below 〉1
                {}% 〈Body font〉
                {}% 〈Indent amount〉2
                {\bfseries\color{white}}% 〈Theorem head font〉
                {}% 〈Punctuation after theorem head 〉
                {\newline}% 〈Space after theorem head 〉3
                {\thmname{#1}\thmnumber{ #2}\thmnote{ $\blacktriangleright$ #3}}% 〈Theorem head spec (can be left empty, meaning ‘normal’ )〉
\theoremstyle{tcb-drop-in-thm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}

\usepackage{tcolorbox} \tcbuselibrary{skins, breakable} \tcolorboxenvironment{theorem}{% colback=gray!25, colframe=gray!90!black, enhanced, top=0mm, overlay={\begin{tcbclipinterior} \fill[gray!90!black] (frame.north west)rectangle ([yshift=-5mm]frame.north east); \end{tcbclipinterior}} } \begin{document}
\begin{theorem}
\label{thm:test}
test can be referenced as \ref{thm:test}
\end{theorem}
\end{document}

which outputsenter image description here

  • 2
    You can use \label more or less anywhere. Please provide a small complete document that shows whatever problem you are having. – David Carlisle Jan 12 '22 at 18:12
  • Thank you David. I have updated with an MWE. – khalid_salad Jan 12 '22 at 18:56
  • 1
    oh OK, but if switching to tcb you need to add that {} argument anyway so why not add the label at that point? you can't simply keep the syntax from amsthm or whatever unless I am missing something? – David Carlisle Jan 12 '22 at 19:25
  • 1
    May be this answer helps: https://tex.stackexchange.com/a/392161/1952 – Ignasi Jan 12 '22 at 19:27
  • Thank you Ignasi, that does help but is a bit messy. I am currently trying to wrap the amsthm's environments in color boxes and create a new \theoremstyle that will look like what I want. It is not quite working as expected yet.

    David, I do not know if there is a way to keep the syntax, but that is primarily what I need right now. Many of my collaborators forget the updated tcb syntax, and I can also use this as a sort of "drop-in replacement" for the style without breaking anything. Additionally, the label autosuggestions in my text editor only work when labels are placed in a \label.

    – khalid_salad Jan 12 '22 at 22:52

0 Answers0