1

What I want to do

I'm trying to frame a theorem and its proof like this:

enter image description here

How I currently do it

The image above was produced by the code below:

\documentclass[a4paper, 12pt]{article}

\usepackage[framemethod=tikz]{mdframed}
\usepackage{amsthm}
\usepackage{xcolor}

\NewDocumentCommand{\newcoloredbox}{mm}{
\newmdenv[
  roundcorner=4pt,
  leftline=true,
  rightline=true, 
  bottomline=true,
  topline=true,
  innertopmargin=7pt,
  linecolor=black,
  linewidth=1,
  backgroundcolor=#2,
]{#1}
}

\newcoloredbox{theorembox}{green!20}
\newcoloredbox{proofbox}{white}

\newtheoremstyle{mytheoremstyle}
  {0pt}
  {\topsep}
  {\itshape}
  {0pt}
  {\bfseries}
  {}
  {5pt plus 1pt minus 1pt}
  {\thmnote{#3}. \hfill \thmname{#1} \thmnumber{#2}}

\theoremstyle{mytheoremstyle}

\newtheorem{theorem_}[equation]{Theorem}

\newenvironment{theorem}[1][]
{
  \begin{theorembox}
  \begin{theorem_}[#1] \leavevmode \\ \noindent
}
{
  \end{theorem_}
  \end{theorembox}
}

\newenvironment{fproof}[1][]
{
  \vspace{-1.8em}
  \begin{proofbox}
  #1
}
{
  \hfill \qedsymbol
  \end{proofbox}
}

\begin{document}

\begin{theorem}[Some nice theorem]
Some extraordinary claim.
\end{theorem}

\begin{fproof}
Some unconvincing proof.
\begin{equation}
x + y = 1.
\end{equation}
\end{fproof}

\end{document}

Problems

There are a couple of problems with the above approach:

  1. The proof-box is moved in contact with the theorem-box simply by using a negative space \vspace{-1.8em} in the fproof environment. I found that value experimentally. Sometimes the proof-box and theorem-box overlap, which is not intended.

  2. The "Theorem 1" on the right does not align together with the equation marker (2). I would like them to be aligned from the right.

These problems are perhaps better seen from the following image:

enter image description here

Question

How can I achieve what I want to do in a robust way?

4
  • The problem 2 seems to be fixed by replacing {5pt plus 1pt minus 1pt} with {0pt}. Not sure why I had it in the first place.
    – kaba
    Nov 18, 2023 at 17:31
  • I know this won't help you solve your problem, but I wonder if your arrangement is to much eye candy. As a mathematician, I think I would prefer to read the same theorems on a quieter page. Mathematics is a calm, quiet and thoughtful endeavor. Nov 18, 2023 at 19:31
  • @BenjaminMcKay This is something new I'm trying, so I'm not sure whether to keep it. I like boxes because they quickly show where the proof or theorem ends, so that you can skip it if you already read it, or don't want to read it. I have red for counterexamples, blue for notes, gray for definitions. Do you object to colors, or to frames?
    – kaba
    Nov 18, 2023 at 19:40
  • I am not sure what I am objecting to. I can appreciate that it might help to see where the proof ends more clearly than the usual presentation. Maybe the colour is too much for me. Nov 18, 2023 at 19:49

2 Answers 2

2

Here's two options with tcolorbox using the environment upper args option to wrap the theorem in a tcolorbox. The first option integrates the theorem and proof in one environment, separated by \tcblower. The second uses two separate environments for the theorem and proof. Note that I moved the period into \thmnote so that if no title is given to the theorem, the period is not printed.

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

\newtheoremstyle{mytheoremstyle}
  {0pt}
  {\topsep}
  {\itshape}
  {0pt}
  {\bfseries}
  {}
  {5pt plus 1pt minus 1pt}
  {\thmnote{#3.}\hfill\thmname{#1} \thmnumber{#2}\newline}

\theoremstyle{mytheoremstyle}
\newtheorem{theorem}{Theorem}
\newtcolorbox{boxtheorem}[1][]{
  environment upper args={theorem}{[#1]},
  after lower=\qed,
  bicolor,
  colback=green!20,
  colbacklower=white,
  }
\newtcolorbox{boxtheoremnoproof}[1][]{
  environment upper args={theorem}{[#1]},
  colback=green!20,
  after skip=0pt,
  }
\newtcolorbox{boxproof}{
  before skip=0pt,
  colback=white,
  after upper=\qed
  }

\begin{document}

\begin{boxtheorem}[Some nice theorem]
Some extraordinary claim.
\tcblower
Some unconvincing proof.
\begin{equation}
  x+y=1
\end{equation}
\end{boxtheorem}

\begin{boxtheoremnoproof}
Another extraordinary claim.
\end{boxtheoremnoproof}

\begin{boxproof}
Another unconvincing proof.
\begin{equation}
  x+y=1
\end{equation}
\end{boxproof}

\end{document}

theorems

1

I found a solution to this as follows:

  • Problem 1: Use skipabove and skipbelow arguments of mdframed to set theorem's skipbelow and proof's skipabove to 0pt. This will place the boxes right after each other. To make the lines coincide, replace \vspace{-1.8em} with \vspace{-1pt} to match the width of the line.

  • Problem 2: replace {5pt plus 1pt minus 1pt} with {0pt} in theorem definition.

enter image description here

The fixed code is as follows:

\documentclass[a4paper, 12pt]{article}

\usepackage[framemethod=tikz]{mdframed}
\usepackage{amsthm}
\usepackage{xcolor}

\NewDocumentCommand{\newcoloredbox}{mmO{1em}O{1em}}{
\newmdenv[
  roundcorner=4pt,
  leftline=true,
  rightline=true, 
  bottomline=true,
  topline=true,
  innertopmargin=7pt,
  linecolor=black,
  linewidth=1,
  backgroundcolor=#2,
  skipabove=#3,
  skipbelow=#4,
]{#1}
}

\newcoloredbox{theorembox}{green!20}[1em][0pt]
\newcoloredbox{proofbox}{white}[0pt][1em]

\newtheoremstyle{mytheoremstyle}
  {0pt}
  {\topsep}
  {\itshape}
  {0pt}
  {\bfseries}
  {}
  {0pt}
  {\thmnote{#3}. \hfill \thmname{#1} \thmnumber{#2}}

\theoremstyle{mytheoremstyle}

\newtheorem{theorem_}[equation]{Theorem}

\newenvironment{theorem}[1][]
{
  \begin{theorembox}
  \begin{theorem_}[#1] \leavevmode \\ \noindent
}
{
  \end{theorem_}
  \end{theorembox}
}

\newenvironment{fproof}[1][]
{
  \vspace{-1pt}
  \begin{proofbox}
  #1
}
{
  \hfill \qedsymbol
  \end{proofbox}
}

\begin{document}

\begin{theorem}[Some nice theorem]
Some extraordinary claim.
\end{theorem}

\begin{fproof}
Some unconvincing proof.
\begin{equation}
x + y = 1.
\end{equation}
\end{fproof}

\end{document}

You must log in to answer this question.

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