如何使用 mdframed 对盒子定理和注释使用几种样式?

如何使用 mdframed 对盒子定理和注释使用几种样式?

我已经修改了这个代码mdframed 包的问题为了满足我的口味:

\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}
}

它运行良好。但是,当我尝试创建另一个名为 remark 的环境时,它会替换“demo”环境的定义(实际上只是标题。我这样做了:

    \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}

编辑:我上面写了一个(可能不是最小的)工作示例。

它不起作用,但我不知道为什么。因为我下周要交论文,所以我请求帮助!谢谢

答案1

您希望\mdcreateextratikz针对两种环境使用不同的方法:

\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}

演示

评论

相关内容