想要一个 mdframed 环境样式,上面有带框架的标题框插入,但没有填充

想要一个 mdframed 环境样式,上面有带框架的标题框插入,但没有填充

这里对其中一个示例进行了轻微的调整mdframed,在定理框上方生成了一个带框的标题插图

\documentclass{article}

\usepackage{amsmath}
%\usepackage{svgcolor}
\usepackage[svgnames]{xcolor}
\usepackage[framemethod=tikz]{mdframed}

\newcounter{Lemma}[section]
\newenvironment{Lemma}[1][]{%
  \stepcounter{Lemma}%
  \ifstrempty{#1}%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[anchor=east,rectangle,fill=blue!20]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[anchor=east,rectangle,fill=blue!20]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma:~\color{Maroon}{#1}};}}%
  }%
  \mdfsetup{innertopmargin=10pt,linecolor=blue!20,%
            linewidth=1pt,topline=true,%
            frametitleaboveskip=\dimexpr-\ht\strutbox\relax,}
  \begin{mdframed}[]\relax%
  }{\end{mdframed}}


\begin{document}

\begin{Lemma}[Distribution of inner products]\label{thm:stokesTheoremGeometricAlgebraII:1420}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{Lemma}

\end{document}

这看起来像:

词干框

我希望标题框具有框架外观而不是填充外观,但不确定如何实现。有示例,例如“示例 5 – TikZ 的复杂示例,其中标题周围有一个独特的框架,但是这个例子对我来说不是一个好的例子,因为它做了很多我不想要的事情(比如覆盖练习环境)。

答案1

改变

  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[anchor=east,rectangle,fill=blue!20]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[anchor=east,rectangle,fill=blue!20]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma:~\color{Maroon}{#1}};}}%
  }%

  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=blue!20,fill=white]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=blue!20,fill=white]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma:~\color{Maroon}{#1}};}}%
  }%

完整示例:

\documentclass{article}

\usepackage{amsmath}
%\usepackage{svgcolor}
\usepackage[svgnames]{xcolor}
\usepackage[framemethod=tikz]{mdframed}

\newcounter{Lemma}[section]
\newenvironment{Lemma}[1][]{%
  \stepcounter{Lemma}%
  \ifstrempty{#1}%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=blue!20,fill=white]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma};}}
  }%
  {\mdfsetup{%
    frametitle={%
      \tikz[baseline=(current bounding box.east),outer sep=0pt]
      \node[line width=1pt,anchor=east,rectangle,draw=blue!20,fill=white]
    {\strut \color{DarkOliveGreen}{Lemma}~\theLemma:~\color{Maroon}{#1}};}}%
  }%
  \mdfsetup{innertopmargin=10pt,linecolor=blue!20,%
            linewidth=1pt,topline=true,%
            frametitleaboveskip=\dimexpr-\ht\strutbox\relax,}
  \begin{mdframed}[]\relax%
  }{\end{mdframed}}


\begin{document}

\begin{Lemma}[Distribution of inner products]\label{thm:stokesTheoremGeometricAlgebraII:1420}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{Lemma}

\begin{Lemma}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{Lemma}

\end{document}

在此处输入图片描述

答案2

我知道这个问题明确是关于mdframed但如果有人对类似的定理环境感兴趣,包tcolorbox是一种替代方案。

Theorem 和类似的环境自初始版本以来就已可用tcolorbox,但最新版本(v 3.05)引入了轻松放置 OP wanted 等标题的功能。使用更复杂的代码已经可以做到这一点,如页面之间的方框文字,但现在更容易做到了。

tcolorbox

\newtcbtheorem[<init options>]{<name>}{<display name>}{<options>}{<prefix>}

定义一个新的定理环境,名为,其标题中将name显示display name,整个格式将由 控制,options并且用于进一步参考的标签将以 开头prefix。因此宏

\newtcbtheorem{myLemma}{Lemma}{lemmastyle}{thm}

定义一个新的myLemma框,自动枚举,标题Lemma <num>为 中定义的方面lemmastyle,并用标签引用thm:anylabel。借助此宏帮助,文本中的定理定义为:

\begin{myLemma}{<lemma description>}{<possible label>}
...
\end{myLemma}

下一个代码展示了一个试图模仿 Gonzalo 的结果的示例。内边距有一些小差异,但总体而言非常相似。

\documentclass{article}

\usepackage{amsmath}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}

\tcbset{
    lemmastyle/.style={enhanced, colback=white, colframe=blue!20, arc=0pt, 
                       fonttitle=\bfseries, description color=Maroon,  
                       colbacktitle=white, coltitle=DarkOliveGreen,    
                       top=\tcboxedtitleheight,
                       boxed title style={arc=0pt},
                       attach boxed title to top left={yshift=-\tcboxedtitleheight/2,
                                                       xshift=4mm}%
                      },
}

\newtcbtheorem{myLemma}{Lemma}{lemmastyle}{thm}

\begin{document}

\begin{myLemma}{Distribution of inner products}{stokesTheoremGeometricAlgebraII:1420}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, 
and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{myLemma}

\begin{myLemma}{}{}
Given two blades $A_s, B_r$ with grades subject to $0 < r < s$, 
and a vector $b$, the inner product distributes according to
\begin{equation*}
    A_s \cdot \left( b \wedge B_r \right) = \left( A_s \cdot b \right) \cdot B_r.
\end{equation*}
\end{myLemma}
\end{document}

在此处输入图片描述

相关内容