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 trying to define a new environment for theorems and I'm using this code:

% Theorem box
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\tikzstyle{thmbox} = [inner sep=1em]
\tikzstyle{thmborder} = [draw=blue, fill=none,line width =1.pt, rounded corners=5pt]

\def\parchmentframe#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}
\fill[thmborder] 
    (A.south east) -- (A.south west) -- 
    (A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}}}

\def\parchmentframetop#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
  (A.south west) -- (A.north west) -- 
  (A.north east) -- (A.south east);
\end{pgfonlayer}}}

\def\parchmentframebottom#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
(A.north west) -- (A.south west) -- 
(A.south east) -- (A.north east);
\end{pgfonlayer}}}

\def\parchmentframemiddle#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
(A.north west) -- (A.south west);
\fill[thmborder]
(A.south east) -- (A.north east);
\end{pgfonlayer}}}

\newenvironment<>{myTheorem}{%
  \def\FrameCommand{\parchmentframe}%
  \def\FirstFrameCommand{\parchmentframetop}%
  \def\LastFrameCommand{\parchmentframebottom}%
  \def\MidFrameCommand{\parchmentframemiddle}%
  \vskip\baselineskip
  \MakeFramed{\FrameRestore}
  \noindent\tikz\node[inner sep=1.2ex, draw=blue, fill=blue!10,
anchor=west, overlay, line width = 1.pt, rounded corners=4pt] at (0em, 1em) 
{\color{LightBlue}{THEOREM}};\par\nobreak}%
{\endMakeFramed}

%%end theorem box

So, when I make the call \begin{myTheorem} I obtain a box with the word THEOREM on top. However when the theorem has a name I would like to have it in my box, maybe with a call like \begin{myTheorem}{Name of the theorem} (similarly to what happens with blocks, where I can decide to have the title or not). How can i modify the code in order to obtain this effect?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

I believe that TikZ and PGF have better ways to cope with framing. However, here's how you can do it:

\newenvironment<>{myTheorem}[1][]{%
  \def\FrameCommand{\parchmentframe}%
  \def\FirstFrameCommand{\parchmentframetop}%
  \def\LastFrameCommand{\parchmentframebottom}%
  \def\MidFrameCommand{\parchmentframemiddle}%
  \vskip\baselineskip
  \MakeFramed{\FrameRestore}
  \noindent\tikz\node[inner sep=1.2ex, draw=blue, fill=blue!10,
anchor=west, overlay, line width = 1.pt, rounded corners=4pt] at (0em, 1em)
{\color{LightBlue}{THEOREM\if\relax\detokenize{#1}\relax\else\space (#1)\fi}};\par\nobreak}%
{\endMakeFramed}

Then call

\begin{frame}
\frametitle{A theorem}
\begin{myTheorem}[True]
All pigs can fly.
\end{myTheorem}
\begin{myTheorem}
No pig can fly.
\end{myTheorem}
\end{frame}

Here's the result (theme Madrid):

enter image description here

Here's the complete code (just added a \colorlet to set what LightBlue is):

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{tikz}
\usepackage{framed}
\colorlet{LightBlue}{blue}

% Theorem box
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\tikzstyle{thmbox} = [inner sep=1em]
\tikzstyle{thmborder} = [draw=blue, fill=none,line width =1.pt, rounded corners=5pt]

\def\parchmentframe#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}
\fill[thmborder] 
    (A.south east) -- (A.south west) -- 
    (A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}}}

\def\parchmentframetop#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
  (A.south west) -- (A.north west) -- 
  (A.north east) -- (A.south east);
\end{pgfonlayer}}}

\def\parchmentframebottom#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
(A.north west) -- (A.south west) -- 
(A.south east) -- (A.north east);
\end{pgfonlayer}}}

\def\parchmentframemiddle#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
(A.north west) -- (A.south west);
\fill[thmborder]
(A.south east) -- (A.north east);
\end{pgfonlayer}}}

\newenvironment<>{myTheorem}[1][]{%
  \def\FrameCommand{\parchmentframe}%
  \def\FirstFrameCommand{\parchmentframetop}%
  \def\LastFrameCommand{\parchmentframebottom}%
  \def\MidFrameCommand{\parchmentframemiddle}%
  \vskip\baselineskip
  \MakeFramed{\FrameRestore}
  \noindent\tikz\node[inner sep=1.2ex, draw=blue, fill=blue!10,
anchor=west, overlay, line width = 1.pt, rounded corners=4pt] at (0em, 1em) 
{\color{LightBlue}{THEOREM\if\relax\detokenize{#1}\relax\else\space (#1)\fi}};\par\nobreak}%
{\endMakeFramed}

%%end theorem box

\begin{document}
\begin{frame}
\frametitle{A theorem}
\begin{myTheorem}[True]
All pigs can fly.
\end{myTheorem}
\begin{myTheorem}
All pigs can fly.
\end{myTheorem}
\end{frame}
\end{document}
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.