Beamer定理新环境

Beamer定理新环境

我正在尝试为定理定义一个新的环境,并使用以下代码:

% Theorem box
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\tikzstyle{thmbox} = [inner sep=1em]
\tikzstyle{thmborder} = [draw=blue, fill=none,line width =1.pt, rounded corners=5pt]

\def\parchmentframe#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}
\fill[thmborder] 
    (A.south east) -- (A.south west) -- 
    (A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}}}

\def\parchmentframetop#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
  (A.south west) -- (A.north west) -- 
  (A.north east) -- (A.south east);
\end{pgfonlayer}}}

\def\parchmentframebottom#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
(A.north west) -- (A.south west) -- 
(A.south east) -- (A.north east);
\end{pgfonlayer}}}

\def\parchmentframemiddle#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
(A.north west) -- (A.south west);
\fill[thmborder]
(A.south east) -- (A.north east);
\end{pgfonlayer}}}

\newenvironment<>{myTheorem}{%
  \def\FrameCommand{\parchmentframe}%
  \def\FirstFrameCommand{\parchmentframetop}%
  \def\LastFrameCommand{\parchmentframebottom}%
  \def\MidFrameCommand{\parchmentframemiddle}%
  \vskip\baselineskip
  \MakeFramed{\FrameRestore}
  \noindent\tikz\node[inner sep=1.2ex, draw=blue, fill=blue!10,
anchor=west, overlay, line width = 1.pt, rounded corners=4pt] at (0em, 1em) 
{\color{LightBlue}{THEOREM}};\par\nobreak}%
{\endMakeFramed}

%%end theorem box

因此,当我拨打电话时\begin{myTheorem},我收到一个带有以下字样的框定理在上面。但是,当定理有名称时,我希望将其放在我的框中,也许使用类似的调用\begin{myTheorem}{Name of the theorem}(类似于块的情况,我可以决定是否要有标题)。我如何修改代码以获得此效果?

答案1

我相信 TikZ 和 PGF 有更好的方法来处理框架。不过,你可以这样做:

\newenvironment<>{myTheorem}[1][]{%
  \def\FrameCommand{\parchmentframe}%
  \def\FirstFrameCommand{\parchmentframetop}%
  \def\LastFrameCommand{\parchmentframebottom}%
  \def\MidFrameCommand{\parchmentframemiddle}%
  \vskip\baselineskip
  \MakeFramed{\FrameRestore}
  \noindent\tikz\node[inner sep=1.2ex, draw=blue, fill=blue!10,
anchor=west, overlay, line width = 1.pt, rounded corners=4pt] at (0em, 1em)
{\color{LightBlue}{THEOREM\if\relax\detokenize{#1}\relax\else\space (#1)\fi}};\par\nobreak}%
{\endMakeFramed}

然后打电话

\begin{frame}
\frametitle{A theorem}
\begin{myTheorem}[True]
All pigs can fly.
\end{myTheorem}
\begin{myTheorem}
No pig can fly.
\end{myTheorem}
\end{frame}

结果如下(主题马德里):

在此处输入图片描述

这是完整的代码(仅添加了一个\colorlet来设置LightBlue):

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{tikz}
\usepackage{framed}
\colorlet{LightBlue}{blue}

% Theorem box
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\tikzstyle{thmbox} = [inner sep=1em]
\tikzstyle{thmborder} = [draw=blue, fill=none,line width =1.pt, rounded corners=5pt]

\def\parchmentframe#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}
\fill[thmborder] 
    (A.south east) -- (A.south west) -- 
    (A.north west) -- (A.north east) -- cycle;
\end{pgfonlayer}}}

\def\parchmentframetop#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
  (A.south west) -- (A.north west) -- 
  (A.north east) -- (A.south east);
\end{pgfonlayer}}}

\def\parchmentframebottom#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
(A.north west) -- (A.south west) -- 
(A.south east) -- (A.north east);
\end{pgfonlayer}}}

\def\parchmentframemiddle#1{
\tikz{
\node[thmbox] (A) {#1};
\begin{pgfonlayer}{background}    
\fill[thmborder]
(A.north west) -- (A.south west);
\fill[thmborder]
(A.south east) -- (A.north east);
\end{pgfonlayer}}}

\newenvironment<>{myTheorem}[1][]{%
  \def\FrameCommand{\parchmentframe}%
  \def\FirstFrameCommand{\parchmentframetop}%
  \def\LastFrameCommand{\parchmentframebottom}%
  \def\MidFrameCommand{\parchmentframemiddle}%
  \vskip\baselineskip
  \MakeFramed{\FrameRestore}
  \noindent\tikz\node[inner sep=1.2ex, draw=blue, fill=blue!10,
anchor=west, overlay, line width = 1.pt, rounded corners=4pt] at (0em, 1em) 
{\color{LightBlue}{THEOREM\if\relax\detokenize{#1}\relax\else\space (#1)\fi}};\par\nobreak}%
{\endMakeFramed}

%%end theorem box

\begin{document}
\begin{frame}
\frametitle{A theorem}
\begin{myTheorem}[True]
All pigs can fly.
\end{myTheorem}
\begin{myTheorem}
All pigs can fly.
\end{myTheorem}
\end{frame}
\end{document}

答案2

newtcbtheorem使用来自 的命令做出的替代定义tcolorbox

新环境myTheo使用两个强制参数,第一个是定理标题,第二个是可能的参考标签。两者都可以留空。

myTheo*该命令还为非编号定理创建了替代环境。

\documentclass{beamer}
\usetheme{Madrid}

\usepackage[most]{tcolorbox}

\newtcbtheorem{myTheorem}{THEOREM}{%
    enhanced,
    arc=5pt,
    boxrule=1pt,
    oversize=-1em,
    colframe=blue,
    colback=white,
    attach boxed title to top left={xshift=5mm,yshift*=-\tcboxedtitleheight/2},
    boxed title style={ colback=blue!10, boxrule=1pt, arc=5pt, left=1mm, right=1mm},
    coltitle=blue,
    separator sign none,
    description delimiters={(}{)}
}{th}

\begin{document}
\begin{frame}
\frametitle{A theorem}
\begin{myTheorem*}{True}{}
All pigs can fly.
\end{myTheorem*}
\begin{myTheorem}{}{}
All pigs can fly.
\end{myTheorem}
\end{frame}
\end{document}

在此处输入图片描述

相关内容