楼主: oliyiyi
8214 33

Latex用mdframed宏包制作精致的定理证明环境 [推广有奖]

版主

泰斗

0%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
271951 个
通用积分
31269.3519
学术水平
1435 点
热心指数
1554 点
信用等级
1345 点
经验
383775 点
帖子
9598
精华
66
在线时间
5468 小时
注册时间
2007-5-21
最后登录
2024-4-18

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

注本文非原创,来自:http://www.latexstudio.net/archives/4482


mdframed宏包可以轻松搞定一个带框的段落样式,而且可以自动跨页。另外,宏包还有很强的定制设计部分,之前,我们分享的一个定理环境就是用的该宏包进行制作的。本文将比较详细的介绍该宏包的使用。

在导言区,引入mdframed宏包且可以直接定义定理,引理,证明,推论这些环境。引入该宏包的时候,推荐选择TikZ的方法来进行框架绘制。

  1. \usepackage[framemethod=TikZ]{mdframed}
复制代码

接下来,我们可以定义一个带计数器的环境了,比如,我们比较熟悉的定理环境,我们通常希望这些定理环境能够和小节的序号关联起来,并且能够在小节标题序号变化的时候能够重置。那么我们可以做如下:

  1. \newcounter{theo}[section]\setcounter{theo}{0}
  2. \renewcommand{\thetheo}{\arabic{section}.\arabic{theo}}
复制代码

按照一般的环境定义,我们可以定义如下环境:

  1. \newenvironment{theo}[2][]{%
  2.     \refstepcounter{theo}

  3.     % Code for box design goes here.

  4. \begin{mdframed}[]\relax}{%
  5. \end{mdframed}}
复制代码

用mdframed设计的定理,计数器的部分是放在一个box里的,因此有时box会有显示定理的具体名称,有时只是单纯的定理序号,因此我们还需要判断不同情况的box设计。我们可以用\ifstringempty{#1}来判断定理里面是否有内容。我们的代码可以改写为:

  1. \newcounter{lem}[section]\setcounter{lem}{0}
  2. \renewcommand{\thelem}{\arabic{section}.\arabic{lem}}
  3. \newenvironment{lem}[2][]{%
  4. \refstepcounter{lem}%
  5. \ifstrempty{#1}%
  6. {\mdfsetup{%
  7. frametitle={%
  8. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  9. \node[anchor=east,rectangle,fill=green!20]
  10. {\strut Lemma~\thelem};}}
  11. }%
  12. {\mdfsetup{%
  13. frametitle={%
  14. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  15. \node[anchor=east,rectangle,fill=green!20]
  16. {\strut Lemma~\thetheo:~#1};}}%
  17. }%
  18. \mdfsetup{innertopmargin=10pt,linecolor=green!20,%
  19. linewidth=2pt,topline=true,%
  20. frametitleaboveskip=\dimexpr-\ht\strutbox\relax
  21. }
  22. \begin{mdframed}[]\relax%
  23. \label{#2}}{\end{mdframed}}
复制代码

同样的方法,我们可以设计证明环境的样式如下:

  1. \newcounter{prf}[section]\setcounter{prf}{0}
  2. \renewcommand{\theprf}{\arabic{section}.\arabic{prf}}
  3. \newenvironment{prf}[2][]{%
  4. \refstepcounter{prf}%
  5. \ifstrempty{#1}%
  6. {\mdfsetup{%
  7. frametitle={%
  8. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  9. \node[anchor=east,rectangle,fill=red!20]
  10. {\strut Proof~\theprf};}}
  11. }%
  12. {\mdfsetup{%
  13. frametitle={%
  14. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  15. \node[anchor=east,rectangle,fill=red!20]
  16. {\strut Proof~\thetheo:~#1};}}%
  17. }%
  18. \mdfsetup{innertopmargin=10pt,linecolor=red!20,%
  19. linewidth=2pt,topline=true,%
  20. frametitleaboveskip=\dimexpr-\ht\strutbox\relax
  21. }
  22. \begin{mdframed}[]\relax%
  23. \label{#2}}{\end{mdframed}}
复制代码

通常证明结束的地方,有个结束符,那么我们可以载入amsthm宏包,定义如下:

  1. % Load package
  2. \usepackage{amsthm}

  3. % Change last line of above code
  4. \begin{mdframed}[]\relax%
  5. \label{#2}}{\qed\end{mdframed}}
复制代码

完整的代码和效果如下:

  1. \documentclass{article}
  2. \usepackage[framemethod=TikZ]{mdframed}
  3. \usepackage{amsthm}
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. %Theorem
  6. \newcounter{theo}[section] \setcounter{theo}{0}
  7. \renewcommand{\thetheo}{\arabic{section}.\arabic{theo}}
  8. \newenvironment{theo}[2][]{%
  9. \refstepcounter{theo}%
  10. \ifstrempty{#1}%
  11. {\mdfsetup{%
  12. frametitle={%
  13. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  14. \node[anchor=east,rectangle,fill=blue!20]
  15. {\strut Theorem~\thetheo};}}
  16. }%
  17. {\mdfsetup{%
  18. frametitle={%
  19. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  20. \node[anchor=east,rectangle,fill=blue!20]
  21. {\strut Theorem~\thetheo:~#1};}}%
  22. }%
  23. \mdfsetup{innertopmargin=10pt,linecolor=blue!20,%
  24. linewidth=2pt,topline=true,%
  25. frametitleaboveskip=\dimexpr-\ht\strutbox\relax
  26. }
  27. \begin{mdframed}[]\relax%
  28. \label{#2}}{\end{mdframed}}
  29. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  30. %Lemma
  31. \newcounter{lem}[section] \setcounter{lem}{0}
  32. \renewcommand{\thelem}{\arabic{section}.\arabic{lem}}
  33. \newenvironment{lem}[2][]{%
  34. \refstepcounter{lem}%
  35. \ifstrempty{#1}%
  36. {\mdfsetup{%
  37. frametitle={%
  38. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  39. \node[anchor=east,rectangle,fill=green!20]
  40. {\strut Lemma~\thelem};}}
  41. }%
  42. {\mdfsetup{%
  43. frametitle={%
  44. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  45. \node[anchor=east,rectangle,fill=green!20]
  46. {\strut Lemma~\thetheo:~#1};}}%
  47. }%
  48. \mdfsetup{innertopmargin=10pt,linecolor=green!20,%
  49. linewidth=2pt,topline=true,%
  50. frametitleaboveskip=\dimexpr-\ht\strutbox\relax
  51. }
  52. \begin{mdframed}[]\relax%
  53. \label{#2}}{\end{mdframed}}
  54. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  55. %Proof
  56. \newcounter{prf}[section]\setcounter{prf}{0}
  57. \renewcommand{\theprf}{\arabic{section}.\arabic{prf}}
  58. \newenvironment{prf}[2][]{%
  59. \refstepcounter{prf}%
  60. \ifstrempty{#1}%
  61. {\mdfsetup{%
  62. frametitle={%
  63. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  64. \node[anchor=east,rectangle,fill=red!20]
  65. {\strut Proof~\theprf};}}
  66. }%
  67. {\mdfsetup{%
  68. frametitle={%
  69. \tikz[baseline=(current bounding box.east),outer sep=0pt]
  70. \node[anchor=east,rectangle,fill=red!20]
  71. {\strut Proof~\thetheo:~#1};}}%
  72. }%
  73. \mdfsetup{innertopmargin=10pt,linecolor=red!20,%
  74. linewidth=2pt,topline=true,%
  75. frametitleaboveskip=\dimexpr-\ht\strutbox\relax
  76. }
  77. \begin{mdframed}[]\relax%
  78. \label{#2}}{\qed\end{mdframed}}
  79. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  80. %Examples
  81. \begin{document}
  82. \section{Theorem and lemma examples with title}
  83. \begin{theo}[Pythagoras' theorem]{thm:pythagoras}
  84. In a right triangle, the square of the hypotenuse is equal to the sum of the squares of the catheti.
  85. $a^2+b^2=c^2$
  86. \end{theo}
  87. In mathematics, the Pythagorean theorem, also known as Pythagoras' theorem (see theorem \ref{thm:pythagoras}), is a relation in Euclidean geometry among the three sides of a right triangle.

  88. \begin{lem}[B\'ezout's identity]{lem:bezout}
  89. Let $a$ and $b$ be nonzero integers and let $d$ be their greatest common divisor. Then there exist integers $x$ and $y$ such that:
  90. $ax+by=d$
  91. \end{lem}
  92. This is a reference to Bezout's lemma \ref{lem:bezout}


  93. \section{Theorem and proof examples without title}

  94. \begin{theo}{thm:theorem1}
  95. There exist two irrational numbers $x$, $y$ such that $x^y$ is rational.
  96. \end{theo}

  97. \begin{prf}{prf:proof1}
  98. If $x=y=\sqrt{2}$ is an example, then we are done; otherwise $\sqrt{2}^{\sqrt{2}}$ is irrational, in which case taking $x=\sqrt{2}^{\sqrt{2}}$ and $y=\sqrt{2}$ gives us:
  99. $\bigg(\sqrt{2}^{\sqrt{2}}\bigg)^{\sqrt{2}}=\sqrt{2}^{\sqrt{2}\sqrt{2}}=\sqrt{2}^{2}=2.$
  100. \end{prf}
  101. \end{document}
复制代码

下载:fancyframetheorem1007


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:LaTeX Frame Late 定理证明 atex 制作

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html
沙发
rrjj101022 发表于 2015-10-14 08:01:59 |只看作者 |坛友微信交流群

回帖奖励 +5

谢谢分享~~~
已有 1 人评分论坛币 收起 理由
oliyiyi + 40 沙发奖励

总评分: 论坛币 + 40   查看全部评分

使用道具

藤椅
condmn 发表于 2015-10-14 08:44:08 |只看作者 |坛友微信交流群

回帖奖励 +5

使用道具

板凳
condmn 发表于 2015-10-14 08:45:32 |只看作者 |坛友微信交流群

使用道具

报纸
zlghs 发表于 2015-10-21 08:49:39 |只看作者 |坛友微信交流群
嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻

使用道具

地板
Ryanz 发表于 2016-1-14 23:27:18 |只看作者 |坛友微信交流群
看着挺不错的

使用道具

7
函数小乖乖 在职认证  发表于 2016-3-14 16:48:37 |只看作者 |坛友微信交流群
支持一下嘿嘿

使用道具

8
函数小乖乖 在职认证  发表于 2016-3-14 16:49:20 |只看作者 |坛友微信交流群

回帖奖励 +5

支持一下嘿嘿

使用道具

9
SMACKDOWN 发表于 2016-3-14 18:22:35 |只看作者 |坛友微信交流群

回帖奖励 +5

谢谢楼主分享。

使用道具

10
SMACKDOWN 发表于 2016-3-14 18:23:07 |只看作者 |坛友微信交流群

回帖奖励 +5

谢谢楼主分享。

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-20 04:11