1. Torbjorn

It would be nice if you changed all the $$..$$ to $..$, the former is not recommended to use in LaTeX.

• tom

Thanks for the heads up. I changed to code accordingly.

2. The code above re-numbers the lemma from 1.1. How can I set the counter so that the lemma’s number continues the theorem’s number? (theorem 1.1, then lemma 1.2, then theorem 1.3, and so on). Thanks.

• tom

Thanks for your question. I assume you refer to the complete code example at the bottom of the article. You’d just have to replace the lemma counter with the theorem counter. Please see the updated lemma code below.

Best, Tom

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Lemma
\newenvironment{lem}[2][]{%
\refstepcounter{theo}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Lemma~\thetheo};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Lemma~\thetheo:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=green!20,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\end{mdframed}}
• Thanks a lot, Tom. It works. I really appreciate your kindness 🙂

3. Kim

If you don’t use the label part in the theorems the first letter in the output will missing.

\begin{lem}[B\'ezout's identity]
Let $a$ and $b$ be nonzero integers and let $d$ be their greatest common divisor. Then there exist integers $x$ and $y$ such that:
$ax+by=d$
\end{lem}
This is a reference to Bezout's lemma \ref{lem:bezout}

Output
et $a$ and $b$ ….. No L!

Thanks a lot for the examples and good blog by the way.

-Kim

• tom

Hi Kim,

Thanks for pointing this out. When the label is not used, just leave the curly brackets empty.

\begin{lem}[B\'ezout's identity]{}

Alternatively, you can also change the lem environment definition.

Best, Tom

4. Jens

Hi Tom,

Thank you for this great article! Since I found it early this year, I use these fancy boxes in every script I write (I´m a math student and make summaries).

Now I like to use such boxes formulas and have problem if my content starts with $…$ .
Then I have a blank line at the beginning.
If I write a text before $…$, then the formula is at the exact same point as without text.

Can you reproduce this issue? If not, I will make my first minimal example 😉

Best wishes
Jens

• tom

Hi Jens,

I can reproduce the extra whitespace with the displaymath environment in the box. There seems to be an extra baselineskip added within mdframed.

Although it is not an elegant solution, my suggestion would be to manually remove the whitespace where necessary.

\begin{theo}{thm:theorem1}
\vspace{-\baselineskip}
$a^2+b^2=c^2$
\end{theo}

HTH,
Tom

• Jens

Hi Tom,

Thanks a lot for this workaround, that helps indeed.

In case someone finds an elegant solution it would be nice if you could share it here.

Bye,
Jens

• tom

You are welcome! To stay informed of future replies, you can subscribe to comments on this article.

Best,
Tom

5. onmikelsen

This theorem box style looks really good, but when i tried to implement this into my project the text above the theorem and the theorem frame gets mashed together. How can i get some vertical space?
https://postimg.org/image/hcrb27dex/

• tom

Hi there,

Thanks for your question. You can add extra vertical space before the box through the skipabove option.

\begin{mdframed}[skipabove=20pt]\relax%
\label{#2}}{\end{mdframed}}

HTH,
Tom

Hi,

I just copy and pasted your code into a document, but now it looks strange – picture in the link below. I would love to use this setup in my maths report, but how do I fix this?

https://postimg.org/image/56gapx713/

BR

Hi again.

I don’t know if you changed anything, but it works when I put it in ShareLaTeX 🙂

BR

• tom

Thanks for letting me know. Perhaps you can try to update your LaTeX distribution to the latest version. I’m happy to try it out, if you send me a minimal working example which produces the boxes in your posted figure.

HTH, Tom

7. Sanjana

Hi Tom,

I don’t want the numbering in the proofs. How do I remove that numbering?

• tom

Hi Sanjana,

Below’s the example from the article without numbering in the proofs.

Best wishes,
Tom

\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Proof environment
\newenvironment{prf}[1][]{%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=red!20]
{\strut Proof};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=red!20]
{\strut Proof:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=red!20,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
}{\qed\end{mdframed}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Examples
\begin{document}
\section{Test}
\begin{prf}
If $x=y=\sqrt{2}$ is an example, then we are done; otherwise $\sqrt{2}^{\sqrt{2}}$ is irrational, in which case taking $x=\sqrt{2}^{\sqrt{2}}$ and $y=\sqrt{2}$ gives us:
$\bigg(\sqrt{2}^{\sqrt{2}}\bigg)^{\sqrt{2}}=\sqrt{2}^{\sqrt{2}\sqrt{2}}=\sqrt{2}^{2}=2.$
\end{prf}
\end{document}
8. Thank you very much for these fancy boxes! I tried defining a definition (and also theorem, lemma and proof) environment using them. I then wrote two definitions in the same section and both are named ‘Definição 1.0’ (same numbering). Do you have any idea why? Maybe I messed the code up? I couldn’t quite understand the numbering code. Here’s my version of the code:

\newcounter{deff}[section]\setcounter{deff}{0}
\renewcommand{\thedeff}{\arabic{section}.\arabic{deff}}
\newenvironment{deff}[2][]{%
\refstepcounter{deff}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definição~\thedeff};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definição~\theteo:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=green!20,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\end{mdframed}}

• Nevermind, found my mistake! The second \theteo was not replaced by \thedeff. Thank you very much again for this tip, I’m using it along with the fncychap package (using Bjornstrup as style) and they look good together. =)

• tom

Thanks for the feedback and for posting your solution. Best, Tom

• tom

Hi Nataliya,

Thanks for getting in touch. Did you try to run the complete example at the end of the article? Please provide your code, so I can take a look.

Best,
Tom

9. Kate

Hi Tom,

I have been trying to use your code to write up note for my exams. My problem is that the text runs out outwidth the box and equations get messed up. I copied you code letter for letter and I have no idea what has gone wrong. Any help would be appreciated,

Kind Regards,

Kate

• tom

Hi Kate,

Please provide a minimal working example for me to reproduce the problem.

Thanks, Tom