7

Here's a slight tweak to one of the mdframed examples that produces a framed title inset above the theorem box

\documentclass{article}

\usepackage{amsmath}
%\usepackage{svgcolor}
\usepackage[svgnames]{xcolor}
\usepackage[framemethod=tikz]{mdframed}

\newcounter{Lemma}[section]
\newenvironment{Lemma}[1][]{%
  \stepcounter{Lemma}%
  \ifstrempty{#1}%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[anchor=east,rectangle,fill=blue!20]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[anchor=east,rectangle,fill=blue!20]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma:~\color{Maroon}{#1}};}}%
  }%
  \mdfsetup{innertopmargin=10pt,linecolor=blue!20,%
            linewidth=1pt,topline=true,%
            frametitleaboveskip=\dimexpr-\ht\strutbox\relax,}
  \begin{mdframed}[]\relax%
  }{\end{mdframed}}


\begin{document}

\begin{Lemma}[Distribution of inner products]\label{thm:stokesTheoremGeometricAlgebraII:1420}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{Lemma}

\end{document}

This looks like:

lemma box

I'd like the title box to have a framed look instead of filled, but am unsure how to do that. There are examples, like " Example 5 – complex example with TikZ, where there is a distinct frame around the title, but that example isn't a good one for me to attempt to build from since it does a lot that I don't want (like overriding the Exercise environment).

Peeter Joot
  • 3,025
  • 2
  • 25
  • 35

2 Answers2

6

Change

  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[anchor=east,rectangle,fill=blue!20]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[anchor=east,rectangle,fill=blue!20]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma:~\color{Maroon}{#1}};}}%
  }%

to

  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=blue!20,fill=white]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=blue!20,fill=white]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma:~\color{Maroon}{#1}};}}%
  }%

A complete example:

\documentclass{article}

\usepackage{amsmath}
%\usepackage{svgcolor}
\usepackage[svgnames]{xcolor}
\usepackage[framemethod=tikz]{mdframed}

\newcounter{Lemma}[section]
\newenvironment{Lemma}[1][]{%
  \stepcounter{Lemma}%
  \ifstrempty{#1}%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=blue!20,fill=white]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=blue!20,fill=white]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma:~\color{Maroon}{#1}};}}%
  }%
  \mdfsetup{innertopmargin=10pt,linecolor=blue!20,%
            linewidth=1pt,topline=true,%
            frametitleaboveskip=\dimexpr-\ht\strutbox\relax,}
  \begin{mdframed}[]\relax%
  }{\end{mdframed}}


\begin{document}

\begin{Lemma}[Distribution of inner products]\label{thm:stokesTheoremGeometricAlgebraII:1420}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{Lemma}

\begin{Lemma}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{Lemma}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
1

I know the question is explicity about mdframed but in case somebody could be interested in similar theorem environments, package tcolorbox is an alternative.

Theorem and similar environments have been available since initial tcolorbox versions, but recent ones (v 3.05) introduced facilities to easily place titles like OP wanted. It was already possible with more complex code as can be seen in Boxed text between pages, but now it's easier to do it.

tcolorbox macro

\newtcbtheorem[<init options>]{<name>}{<display name>}{<options>}{<prefix>}

defines a new theorem environment called name which will show display name in its title, the whole format will be controlled with options and labels for further reference will be preceded by a prefix. Therefore macro

\newtcbtheorem{myLemma}{Lemma}{lemmastyle}{thm}

defines a new myLemma box, auto enumerated, titled Lemma <num> with aspect defined in lemmastyle and referenced with labels thm:anylabel. With this macro help, theorems in text are defined with:

\begin{myLemma}{<lemma description>}{<possible label>}
...
\end{myLemma}

Next code shows an example which tries to mimmic Gonzalo's results. There are some little differences with inner margins but the general aspect is quite similar.

\documentclass{article}

\usepackage{amsmath}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}

\tcbset{
    lemmastyle/.style={enhanced, colback=white, colframe=blue!20, arc=0pt, 
                       fonttitle=\bfseries, description color=Maroon,  
                       colbacktitle=white, coltitle=DarkOliveGreen,    
                       top=\tcboxedtitleheight,
                       boxed title style={arc=0pt},
                       attach boxed title to top left={yshift=-\tcboxedtitleheight/2,
                                                       xshift=4mm}%
                      },
}

\newtcbtheorem{myLemma}{Lemma}{lemmastyle}{thm}

\begin{document}

\begin{myLemma}{Distribution of inner products}{stokesTheoremGeometricAlgebraII:1420}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, 
and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{myLemma}

\begin{myLemma}{}{}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, 
and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{myLemma}
\end{document}

enter image description here

Ignasi
  • 136,588