我希望能够排版一个带有精美边框的紧密框定公式。
到目前为止,我的进展是制作一个带有我想要的花式边框(使用 tikz)的盒子(使用 mdframed),但它不是紧紧围绕其内容,而是始终延伸到线的宽度。
\documentclass{beamer}
\mode<presentation>
\usetheme{Madrid}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
% Caution-tape frame style
\mdfdefinestyle{caution}{linewidth=10pt,
tikzsetting={decorate,decoration={markings,
mark=between positions 0 and 1 step 6pt
with {
\fill[yellow] (-3pt,-2pt) -- (0pt,-2pt) -- (3pt,2pt) -- (0pt,2pt) -- (-3pt,-2pt);
\fill[black] (0pt,-2pt) -- (3pt,-2pt) -- (6pt,2pt) -- (3pt,2pt) -- (0pt,-2pt);
}}}}
\begin{document}
\begin{frame}{testing}
\begin{mdframed}[style=caution]
$\frac{d}{dx} x^2 = 2x$
\end{mdframed}
\end{frame}
\end{document}
我不确定 mdframed 是否能够绘制一个紧密的框。如果可以,我将不胜感激任何指向正确咒语的指针。如果不行,我需要一个替代方案。我查看了 empheq 包,它允许指定自定义“框命令”,但我不知道如何将我花哨的边框代码转换为它想要的形式。
此外,我希望可以将该框嵌入一行文本中,例如:
\begin{frame}{testing}
My cool equation is \begin{foo}$\frac{d}{dx} x^2 = 2x$\end{foo}, isn't it neat?
\end{frame}
答案1
我可以提供一个使用包environ
和的解决方案varwidth
。将 mdframed 放入 minipage 可防止其占用整行,因此可以将其嵌入到其他文本中。
\documentclass{beamer}
\mode<presentation>
\usetheme{Madrid}
\usepackage{calc}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
% Caution-tape frame style
\mdfdefinestyle{caution}{linewidth=10pt,
tikzsetting={decorate,decoration={markings,
mark=between positions 0 and 1 step 6pt
with {
\fill[yellow] (-3pt,-2pt) -- (0pt,-2pt) -- (3pt,2pt) -- (0pt,2pt) -- (-3pt,-2pt);
\fill[black] (0pt,-2pt) -- (3pt,-2pt) -- (6pt,2pt) -- (3pt,2pt) -- (0pt,-2pt);
}}},
innerleftmargin=5pt,innerrightmargin=5pt,align=center,nobreak,
}
\usepackage{environ,varwidth}
\newsavebox\MyTempBox
\NewEnviron{caution}{%
\savebox\MyTempBox{%
\begin{varwidth}{\linewidth}
\BODY
\end{varwidth}}%
\begin{minipage}{\dimexpr\wd\MyTempBox+12pt\relax}
\begin{mdframed}[style=caution,userdefinedwidth=\dimexpr\wd\MyTempBox+12pt\relax]
\BODY
\end{mdframed}%
\end{minipage}
}%
\begin{document}
\begin{frame}{testing}
My cool equation is \begin{caution}$\frac{d}{dx} x^2 = 2x$\end{caution}, isn't it neat?
\end{frame}
\end{document}