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.

I'm looking for a way to style a theorem as shown here.

enter image description here

The code there works if I want the theorem number in the heading box, but I also want to be able to pass a custom theorem name to add to that heading box. The optional argument seems to be showing up as part of the #1, so how do I separate it so that I can put it elsewhere?

The code I'm currently using (from the same link given above)

\usepackage{graphicx,textpos, a4wide}
\usepackage{helvet, amssymb}

\usepackage{tikz}
\usetikzlibrary{shadows}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations}

\usepackage{framed}
\usepackage[framed, amsthm]{ntheorem}

\theoremclass{Theorem}
\theoremstyle{empty}
\newcommand{\thmbox}[1]{
  \tikzstyle{thmbox} = [rectangle, rounded corners, draw=black, fill=gray!20, inner sep=15pt, drop shadow={fill=black, opacity=.5}]%
  \tikzstyle{fancytitle} =[fill=white, text=black, rectangle, rounded corners, draw= black]%
  \noindent%
  \begin{tikzpicture}%
    \node [thmbox] (box){%
      \begin{minipage}{.91\textwidth}%
        \textit{#1}%
      \end{minipage}%
    };%
  \node[fancytitle, right=10pt] at (box.north west) {\textbf{Theorem \thetheorem}%
    };%
    \end{tikzpicture}}

\def\theoremframecommand{\thmbox}
\newshadedtheorem{theorem}{Theorem}

And in the body:

\begin{theorem}[abc]
Hello
\end{theorem}
share|improve this question
3  
Example four of the file mdframed-example-tikz.pdf –  Marco Daniel Jan 28 '12 at 15:58
    
@MarcoDaniel I think that's an answer :) –  cmhughes Jan 28 '12 at 17:35
    
@MarcoDaniel Wouldn't it be better to use typewriter type and the listings option columns=fullflexible in the source code? As they are it's impossible to copy-paste the code (and it's unreadable). –  egreg Jan 29 '12 at 0:03
    
@egreg: I will change the settings of listings. You are completely right. –  Marco Daniel Jan 29 '12 at 9:23
    
@MarcoDaniel An answer would be nice. :-) –  lockstep Mar 3 '12 at 22:25
add comment

1 Answer

up vote 1 down vote accepted

Based of the comments I created an approach.

The important part of the code is the redefinition of \mdfcreateextratikz. The package provides this command to put extra material somewhere. The coordinates O and P are used internal. In the file md-frame-1.mdf you can find their meaning.

\documentclass{article}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shadows,shadings}
\usepackage{lipsum}

\newcounter{theorem}
\renewcommand\thetheorem{Theorem~\arabic{theorem}}
\makeatletter
\mdf@dolist{\mdf@do@stringoption}{%
    {theoremtitle=={}}%
}
\renewrobustcmd\mdfcreateextratikz{%
      \node[anchor=west,rounded corners,draw,thick,shading=axis,left color=blue!20,xshift=1cm,minimum height=.7cm,minimum width=2cm] at (P-|O) 
              {~\mdf@frametitlefont{\thetheorem}%
                  \ifdefempty{\mdf@theoremtitle}%
                  {~}%
                  {:~\mdf@theoremtitle~}%
              };
}
\makeatother
\mdfdefinestyle{theoremstyle}{%
outerlinewidth=1pt,
innerlinewidth=0pt,
roundcorner=2pt,
linecolor=black,
shadow=true,
tikzsetting={shading=axis,top color=gray!20},
innertopmargin=1.2\baselineskip,
skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
needspace=3\baselineskip,
frametitlefont=\sffamily\bfseries,
settings={\global\stepcounter{theorem}},
}
\newenvironment{theorem}[1][]
{\begin{mdframed}[style=theoremstyle,theoremtitle={#1}]\relax}{\end{mdframed}}

\begin{document}
\begin{theorem}
\lipsum[1]
\end{theorem}
\begin{theorem}[Title of the Theorem]
\lipsum[1]
\end{theorem}
\end{document}

This results in:

enter image description here

share|improve this answer
add comment

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.