2

I have modified this code Issue with mdframed package in order to satisfy my taste:

\documentclass[a4paper,10pt]{memoir}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shadows,shadings}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}

\newcounter{demo_counter}

\renewcommand\thetheorem{Demonstration ~\arabic{demo_counter}}


\makeatletter
\mdf@dolist{\mdf@do@stringoption}{%
{theoremtitle=={}}%
}
\renewrobustcmd\mdfcreateextratikz{%
  \node[anchor=west,rounded corners,draw=orange,thick,fill=blue!20,xshift=2cm,minimum height=.7cm,minimum width=2cm] at (P-|O) 
      {~\mdf@frametitlefont{\thetheorem}%
          \ifdefempty{\mdf@theoremtitle}%
          {~}%
          {:~\mdf@theoremtitle~}%
      };
}
\makeatother

\mdfdefinestyle{theoremstyle}{% 
outerlinewidth=1pt,
innerlinewidth=3pt,
roundcorner=5pt,
linecolor=orange,
splittopskip=1cm,         % THIS IS THE REQUIRED OPTION FOR SPACE ABOVE THE SPLIT ON THE SECOND PAGE
splitbottomskip=1cm,      % THIS IS THE REQUIRED OPTION FOR SPACE BELOW THE SPLIT ON THE FIRST PAGE 
tikzsetting={fill=blue!5},
innertopmargin=1.2\baselineskip,
skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
needspace=3\baselineskip,
frametitlefont=\sffamily\bfseries,
settings={\global\stepcounter{demo_counter}},
}

\newenvironment{demo}[1][]
{\begin{mdframed}[style=theoremstyle,theoremtitle={#1}]
\relax}{
\end{mdframed}
}

It works nicely. However, when I try to create another environment called remark, it replace the definition of the "demo" environment (actually just the title. I did that:

    \documentclass[a4paper,10pt]{memoir}
\usepackage[utf8]{inputenc}

\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shadows,shadings}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}

\newcounter{demo_counter}
\newcounter{remark_counter}

\newcommand\thetheorem{Demonstration ~\arabic{demo_counter}}
\newcommand\theremark{Remark ~\arabic{remark_counter}}

\makeatletter
\mdf@dolist{\mdf@do@stringoption}{%
{theoremtitle=={}}%
  }

\mdf@dolist{\mdf@do@stringoption}{%
{remarktitle=={}}%
  }        

\renewrobustcmd\mdfcreateextratikz{%
  \node[anchor=west,rounded corners,draw=orange,thick,fill=blue!20,xshift=2cm,minimum height=.7cm,minimum width=2cm] at (P-|O) 
      {~\mdf@frametitlefont{\thetheorem}%
      \ifdefempty{\mdf@theoremtitle}%
      {~}%
      {:~\mdf@theoremtitle~}%
      };
}

\renewrobustcmd\mdfcreateextratikz{%
  \node[anchor=west,rounded corners,draw=green,thick,fill=blue!20,xshift=2cm,minimum height=.7cm,minimum width=2cm] at (P-|O) 
      {~\mdf@frametitlefont{\theremark}%
      \ifdefempty{\mdf@remarktitle}%
      {~}%
      {:~\mdf@remarktitle~}%
      };
}

\makeatother

\mdfdefinestyle{theoremstyle}{% 
  outerlinewidth=1pt,
  innerlinewidth=3pt,
  roundcorner=5pt,
  linecolor=orange,
  splittopskip=1cm,         % THIS IS THE REQUIRED OPTION FOR SPACE ABOVE THE SPLIT ON THE SECOND PAGE
  splitbottomskip=1cm,      % THIS IS THE REQUIRED OPTION FOR SPACE BELOW THE SPLIT ON THE FIRST PAGE 
  tikzsetting={fill=blue!5},
  innertopmargin=1.2\baselineskip,
  skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
  needspace=3\baselineskip,
  frametitlefont=\sffamily\bfseries,
  settings={\global\stepcounter{demo_counter}},
  }

\mdfdefinestyle{remarkstyle}{% 
  outerlinewidth=1pt,
  innerlinewidth=3pt,
  roundcorner=5pt,
  linecolor=green,
  splittopskip=1cm,         
  splitbottomskip=1cm,     
  tikzsetting={fill=blue!5},
  innertopmargin=1.2\baselineskip,
  skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
  needspace=3\baselineskip,
  frametitlefont=\sffamily\bfseries,
  settings={\global\stepcounter{remark_counter}},
  }

\newenvironment{demo}[1][]
  {\begin{mdframed}[style=theoremstyle,theoremtitle={#1}]
  \relax}{
  \end{mdframed}
  }

\newenvironment{remark}[1][]
  {\begin{mdframed}[style=remarkstyle,remarktitle={#1}]
  \relax}{
  \end{mdframed}
  }


\begin{document}
  \chapter{chapter one}
\begin{demo}
\lipsum
\end{demo}

\begin{remark}
\lipsum
\end{remark}

\end{document}

Edit: I have written a (probably not minimal) working example above.

It does not work but i cannot figure out why. And because I shall send my thesis on next week, I am beggi... asking for some help! Thank you

  • Please make your example compilable. We can not work with snippets as it would just be a guessing around. Btw. your code does not look minimal. Please reduce it until you are just showing the disturbing part of code. Thanks. – LaRiFaRi Sep 2 '14 at 14:52
  • I am sorry, I forgot to put the begin document part. I will edit my post. It is minimal because I do not know what is responsible for the problem. Note that I should send my thesis very soon and that is why I did not take a lot of time to look for the answer, and that is why I am asking for some help. Thanks. – nbi Sep 4 '14 at 9:49
3

You want to use different \mdcreateextratikz for the two environments:

\documentclass[a4paper,10pt]{memoir}
\usepackage[utf8]{inputenc}

\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{shadows,shadings}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}

\newcounter{demo_counter}
\newcounter{remark_counter}

\newcommand\thetheorem{Demonstration ~\arabic{demo_counter}}
\newcommand\theremark{Remark ~\arabic{remark_counter}}

\makeatletter
\mdf@dolist{\mdf@do@stringoption}{%
  {theoremtitle=={}}%
}

\mdf@dolist{\mdf@do@stringoption}{%
  {remarktitle=={}}%
}        

\newrobustcmd\mdfcreatetheoremextratikz{%
  \node[anchor=west,rounded corners,draw=orange,thick,fill=blue!20,xshift=2cm,minimum height=.7cm,minimum width=2cm] at (P-|O) 
      {~\mdf@frametitlefont{\thetheorem}%
      \ifdefempty{\mdf@theoremtitle}%
      {~}%
      {:~\mdf@theoremtitle~}%
      };
}

\newrobustcmd\mdfcreateremarkextratikz{%
  \node[anchor=west,rounded corners,draw=green,thick,fill=blue!20,xshift=2cm,minimum height=.7cm,minimum width=2cm] at (P-|O) 
      {~\mdf@frametitlefont{\theremark}%
      \ifdefempty{\mdf@remarktitle}%
      {~}%
      {:~\mdf@remarktitle~}%
      };
}

\makeatother

\newcommand{\doextratikz}[1]{%
  \letcs\mdfcreateextratikz{mdfcreate#1extratikz}%
}

\mdfdefinestyle{theoremstyle}{% 
  outerlinewidth=1pt,
  innerlinewidth=3pt,
  roundcorner=5pt,
  linecolor=orange,
  splittopskip=1cm,         % THIS IS THE REQUIRED OPTION FOR SPACE ABOVE THE SPLIT ON THE SECOND PAGE
  splitbottomskip=1cm,      % THIS IS THE REQUIRED OPTION FOR SPACE BELOW THE SPLIT ON THE FIRST PAGE 
  tikzsetting={fill=blue!5},
  innertopmargin=1.2\baselineskip,
  skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
  needspace=3\baselineskip,
  frametitlefont=\sffamily\bfseries,
  settings={\stepcounter{demo_counter}\doextratikz{theorem}},
  }

\mdfdefinestyle{remarkstyle}{% 
  outerlinewidth=1pt,
  innerlinewidth=3pt,
  roundcorner=5pt,
  linecolor=green,
  splittopskip=1cm,         
  splitbottomskip=1cm,     
  tikzsetting={fill=blue!5},
  innertopmargin=1.2\baselineskip,
  skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
  needspace=3\baselineskip,
  frametitlefont=\sffamily\bfseries,
  settings={\stepcounter{remark_counter}\doextratikz{remark}},
  }

\newenvironment{demo}[1][]
  {\begin{mdframed}[style=theoremstyle,theoremtitle={#1}]
  \relax}{
  \end{mdframed}
  }

\newenvironment{remark}[1][]
  {\begin{mdframed}[style=remarkstyle,remarktitle={#1}]
  \relax}{
  \end{mdframed}
  }


\begin{document}
  \chapter{chapter one}
\begin{demo}
\lipsum
\end{demo}

\begin{remark}
\lipsum
\end{remark}

\end{document}

demo

remark

  • Thank you very much! I understand why it did not work before. There is one more problem: !(hostingpics.net/viewer.php?id=196666Capturedu20140904165552.png) the remark environment is fine in the first page, but then there is an empty page, then again the remark frame, but without the background, and finally it is good again. I guess, I did something wrong (again) in copying the Demo environment. Do you have an idea ? thank you again! – nbi Sep 4 '14 at 15:01
  • @nbi No, sorry. – egreg Sep 4 '14 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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