1

The snippet below has been obtained nesting two environments taken from amsthm and tcolorbox.

I would like to redefine the environment theorem to produce the same output (I can only modify the preamble).

enter image description here

\documentclass{article}
\usepackage{amsthm}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newtheoremstyle{mystyle}{0ex}{0ex}{}{}{\bfseries}{}{1.5ex}{\llap{\thmnumber{#2}\hskip2mm}\thmname{#1}\thmnote{\bfseries{}#3}}
\theoremstyle{mystyle}
\newtheorem{theorem}{Theorem}

\parindent0pt
\begin{document}
\lipsum[1][1-2]

\begin{tcolorbox}[colback=red!5!white, colframe=red!50!black, extrude left by=5ex, left=5ex, boxsep=0ex]
\begin{theorem}
\lipsum[1][3]
\end{theorem}
\end{tcolorbox}

\lipsum[1][4-5]
\end{document}
1
  • 1
    Have a look at \newtcbtheorem from the tcolorbox package. This way you don't have to nest environments. Commented Jun 30 at 12:14

2 Answers 2

2

You can use \tcolorboxenvironment.

\documentclass{article}
\usepackage{amsthm}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newtheoremstyle{mystyle}
  {0ex}
  {0ex}
  {}
  {}
  {\bfseries}
  {}
  {1.5ex}
  {\llap{\thmnumber{#2}\hspace{2mm}}\thmname{#1}\thmnote{\bfseries #3}}
\theoremstyle{mystyle}
\newtheorem{theorem}{Theorem}
\tcolorboxenvironment{theorem}{
  colback=red!5!white,
  colframe=red!50!black,
  extrude left by=5ex,
  left=5ex,
  boxsep=0pt
}

\begin{document}

\lipsum[1][1-2]

\begin{theorem}
\lipsum[1][3]
\end{theorem}

\lipsum[1][4-5]

\end{document}

enter image description here

If you need to do the same to several theorem-like environments, you can avoid code duplication.

\documentclass{article}
\usepackage{amsthm}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newtheoremstyle{mystyle}
  {0ex}
  {0ex}
  {}
  {}
  {\bfseries}
  {}
  {1.5ex}
  {\llap{\thmnumber{#2}\hskip2mm}\thmname{#1}\thmnote{\bfseries{}#3}}
\theoremstyle{mystyle}
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}[theorem]{Proposition}

\tcbset{
  mytheorem/.style={
    colback=red!5!white,
    colframe=red!50!black,
    extrude left by=5ex,
    left=5ex,
    boxsep=0pt,
  },
}
\tcolorboxenvironment{theorem}{mytheorem}
\tcolorboxenvironment{proposition}{mytheorem}

\begin{document}

\lipsum[1][1-2]

\begin{proposition}
\lipsum[1][3]
\end{proposition}

\lipsum[1][1-2]

\begin{theorem}
\lipsum[1][3]
\end{theorem}

\lipsum[1][4-5]

\end{document}

enter image description here

1
  • Great, this is an elegant solution! Commented Jun 30 at 16:16
2
\documentclass{article}
\usepackage{amsthm}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newtheoremstyle{mystyle}{0ex}{0ex}{}{}{\bfseries}{}{1.5ex}{\llap{\thmnumber{#2}\hskip2mm}\thmname{#1}\thmnote{ \bfseries(#3)}}
\theoremstyle{mystyle}
\newtheorem{thm}{Theorem}
\newenvironment{theorem}[1][]
{
\begin{tcolorbox}[colback=red!5!white, colframe=red!50!black, extrude left by=5ex, left=5ex, boxsep=0ex]
\begin{thm}[#1]
}{
\end{thm}
\end{tcolorbox}
}

\parindent0pt

\begin{document}

\lipsum[1][1-2]

\begin{theorem}
\lipsum[1][3]
\end{theorem}

\lipsum[1][4-5]

\begin{theorem}[Cauchy]
\lipsum[1][3]
\end{theorem}

\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 .