Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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

share|improve this answer
    
thanks. btw. Looks like the first \node line should be: \node[anchor=east,rectangle,draw=blue!20,fill=white] (ie. still want a box for an unnamed, but still numbered begin/end block). –  Peeter Joot Apr 14 at 18:50
    
@PeeterJoot ooops! You're right. I forgot to update the code there. I've fixed it. –  Gonzalo Medina Apr 14 at 18:52
    
@PeeterJoot I introduced another minor modification, so now the rules used in the frame for the title have the same thickness as the rules used for the general frame. –  Gonzalo Medina Apr 14 at 19:00
    
Very nice, that looks better. –  Peeter Joot Apr 14 at 19:06

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.