Beamer 中的方程式、箭头和注释

Beamer 中的方程式、箭头和注释

我喜欢 tikZ 与 beamer 结合使用时突出显示方程式的方式(它与 beamerarticle 和 article 模式配合得很好),例如TeX示例 我经常使用此功能,但我认为代码很难“即时”操作。我想创建一个newcommand(?)\EqNComments(方程式和注释),我可以在代码中轻松调用。

    \EqNComments
    {$\Delta$}{=}{Le point Delta}
    {$\mathcal{N}(d_1)$}{+}{Hedge ratio}
    {$K.e^{-rt}.\mathcal{N}(d_2)$}{}{Strike actualised}

在此处输入图片描述

这是与 3x3 元素配合得很好的 MWE。

  1. newcommand我被参数限制为 9
  2. 我无法输入\foreach优化我的代码
  3. 一定有更智能的方法来处理此事......

    \documentclass{beamer}
    %\documentclass[11pt,twoside]{article}
    %\usepackage[envcountsect]{beamerarticle}
    \usetheme{Warsaw}
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{tikz}
    \usetikzlibrary{arrows,shapes}
    
    \tikzset{
        Col1/.style= {fill=blue!20,anchor=base,rounded corners=2pt},
        Col2/.style= {Col1, fill=red!20},
        Col3/.style= {Col1, fill=green!20},
    }
    
    \newcommand{\EqNComments}[9]
    {
    
    \tikzstyle{every picture}+=[remember picture]
    \tikzstyle{na} = [baseline=-.5ex]
    
    \begin{frame}
        \begin{equation}
                        \tikz[baseline] {\node[Col1] (d1) {#1};}  #2
                        \tikz[baseline] {\node[Col2] (d2) {#4};}  #5
                        \tikz[baseline] {\node[Col3] (d3) {#7};}  #8                    
    %                   \tikz[baseline] {\node[Col3] (d4) {#10};} #11                    
        \end{equation}
    
        \begin{itemize}
            \item #3 
            \tikz[na] \node[coordinate] (s1) {};
            \item #6 
            \tikz[na] \node[coordinate] (s2) {};        
            \item #9  
            \tikz[na] \node[coordinate] (s3) {};
    %       \item #12  
    %       \tikz[na] \node[coordinate] (s4) {};        
        \end{itemize}
    
        \begin{tikzpicture}[overlay]
            \path[->] (s1) edge [bend left]     (d1);
            \path[->] (s2) edge [bend right]    (d2);
            \path[->] (s3) edge [out=0, in=-90] (d3);
    %       \path[->] (s4) edge [out=0, in=-90] (d4);       
        \end{tikzpicture}
    \end{frame}
    } 
    
    \begin{document}
    
    \EqNComments
    {$\Delta$}{=}{Le point Delta}
    {$\mathcal{N}(d_1)$}{+}{Hedge ratio}
    {$K.e^{-rt}.\mathcal{N}(d_2)$}{-}{Strike actualised}
    %{dividendes}{.}{Not working here if I try to extend the command to 12 arguments}
    
    \end{document}
    

答案1

这做了类似的事情。它使用tikzmark库,这是一个更好的工具,因为除其他外,它不会破坏间距并检测我们所处的模式。任何数量都可以用

\tmn{<quantity>}{<annotation>}

只要你将它们放在AnnotatedEquation环境中,它们就会像你所做的一样被列表注释。节点将使用样式等Col1Col2只要它们被定义。你可以使用可选参数来添加一些键。

\documentclass{beamer} 
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcounter{mytn}
\makeatletter
\newcommand{\tmn}[3][]{\stepcounter{mytn}%
\tikzmarknode[Col\the\numexpr\value{mytn}-\mytn@start\relax/.try,inner xsep=2pt,%
minimum height=1.6em,#1]{mytn-\number\value{mytn}}{#2}%
\expandafter\gdef\csname tmn@annot@\number\value{mytn}\endcsname{#3}}
\newenvironment{AnnotatedEquation}{\edef\mytn@start{\number\value{mytn}}%
\begin{equation}}{\end{equation}%
\edef\mytn@end{\number\value{mytn}}%
\ifnum\mytn@end>\mytn@start
\begin{itemize}
 \foreach \X in {\the\numexpr\mytn@start+1,...,\mytn@end} 
 {\item \tikzmarknode{mytn-annot-\X}{\csname tmn@annot@\X\endcsname}%
 \begin{tikzpicture}[overlay,remember picture]
  \draw[-stealth] (mytn-annot-\X.east) to[out=0,in=-90] (mytn-\X.south);
 \end{tikzpicture}} 
\end{itemize}
\fi}
\makeatother
\tikzset{ Col1/.style= {fill=blue!20,anchor=base,rounded corners=2pt}, 
Col2/.style= {Col1, fill=red!20}, 
Col3/.style= {Col1, fill=green!20}, }
\begin{document}
\begin{frame}[t]
\frametitle{Some annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
\end{AnnotatedEquation}
\end{frame}
\begin{frame}[t]
\frametitle{Another annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
 +\tmn{\xi}{a Weyl spinor}
 +\tmn{\eta}{another Weyl spinor}
\end{AnnotatedEquation}
\end{frame}
\end{document}

在此处输入图片描述

这是一个可以与之兼容的版本external

\documentclass{beamer} 
\usepackage{tikz}
\usetikzlibrary{tikzmark,external}
\newcounter{mytn}
\makeatletter
\newcommand{\tmn}[3][]{\stepcounter{mytn}%
\tikzmarknode[Col\the\numexpr\value{mytn}-\mytn@start\relax/.try,inner xsep=2pt,%
minimum height=1.6em,#1]{mytn-\number\value{mytn}}{#2}%
\expandafter\gdef\csname tmn@annot@\number\value{mytn}\endcsname{#3}}
\newenvironment{AnnotatedEquation}{\edef\mytn@start{\number\value{mytn}}%
\tikzexternaldisable
\begin{equation}}{\end{equation}%
\edef\mytn@end{\number\value{mytn}}%
\ifnum\mytn@end>\mytn@start
\begin{itemize}
 \foreach \X in {\the\numexpr\mytn@start+1,...,\mytn@end} 
 {\item \tikzmarknode{mytn-annot-\X}{\csname tmn@annot@\X\endcsname}%
 \begin{tikzpicture}[overlay,remember picture]
  \draw[-stealth] (mytn-annot-\X.east) to[out=0,in=-90] (mytn-\X.south);
 \end{tikzpicture}} 
\end{itemize}
\fi\tikzexternalenable}
\makeatother
\tikzset{ Col1/.style= {fill=blue!20,anchor=base,rounded corners=2pt}, 
Col2/.style= {Col1, fill=red!20}, 
Col3/.style= {Col1, fill=green!20}, }
\begin{document}
\begin{frame}[t]
\frametitle{Some annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
\end{AnnotatedEquation}
\end{frame}
\begin{frame}[t]
\frametitle{Another annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
 +\tmn{\xi}{a Weyl spinor}
 +\tmn{\eta}{another Weyl spinor}
\end{AnnotatedEquation}
\end{frame}
\end{document}

附录:这是一个更复杂但也更通用的版本,它允许人们调整箭头。这可以通过使用键来完成special arrow。例如,

\tmn[special arrow={out=90,annotations/out anchor=north}]{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}

指示箭头从注释文本的北边出来,并以 90 度角离开。默认值为东锚点和 0 度。这在处理分数分子时特别有用。

\documentclass{beamer} 
\usepackage{tikz}
\usetikzlibrary{tikzmark,external}
\newcounter{mytn}
\makeatletter
\newcommand{\tmn}[3][]{\stepcounter{mytn}%
\tikzmarknode[annotations/Col\the\numexpr\value{mytn}-\mytn@start\relax/.try,inner xsep=2pt,%
minimum height=1.6em,#1]{mytn-\number\value{mytn}}{#2}%
\expandafter\gdef\csname tmn@annot@\number\value{mytn}\endcsname{#3}}
\tikzset{special arrow/.code={%
\expandafter\xdef\csname tmn@arrow@style@\number\value{mytn}\endcsname{#1}}}
\newenvironment{AnnotatedEquation}{\edef\mytn@start{\number\value{mytn}}%
\tikzexternaldisable
\begin{equation}}{\end{equation}%
\edef\mytn@end{\number\value{mytn}}%
\ifnum\mytn@end>\mytn@start
\begin{itemize}
 \foreach \X in {\the\numexpr\mytn@start+1,...,\mytn@end} 
 {\item \tikzmarknode{mytn-annot-\X}{\csname tmn@annot@\X\endcsname}%
 \begin{tikzpicture}[overlay,remember picture]
  \ifcsname tmn@arrow@style@\X\noexpand\endcsname
   \draw[-stealth,out=0,in=-90,
    style/.expanded=\csname tmn@arrow@style@\X\noexpand\endcsname] 
    (mytn-annot-\X.\pgfkeysvalueof{/tikz/annotations/out anchor}) 
    to (mytn-\X.\pgfkeysvalueof{/tikz/annotations/in anchor});
  \else
   \draw[-stealth,out=0,in=-90] (mytn-annot-\X.\pgfkeysvalueof{/tikz/annotations/out anchor})
    to (mytn-\X.\pgfkeysvalueof{/tikz/annotations/in anchor});
  \fi
 \end{tikzpicture}} 
\end{itemize}
\fi\tikzexternalenable}
\makeatother
\tikzset{annotations/.cd, 
Col1/.style= {fill=blue!20,anchor=base,rounded corners=2pt}, 
Col2/.style= {annotations/Col1, fill=red!20}, 
Col3/.style= {annotations/Col1, fill=green!20}, 
in anchor/.initial=south,out anchor/.initial=east}
\begin{document}
\begin{frame}[t]
\frametitle{Some annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
\end{AnnotatedEquation}
\end{frame}
\begin{frame}[t]
\frametitle{Another annotated equation}
\begin{AnnotatedEquation}
 \tmn[special arrow={out=90,annotations/out anchor=north}]{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
 +\frac{\tmn[special arrow={in=-160,annotations/in anchor=west}]{\xi}{a Weyl spinor}}{\tmn{\eta}{another Weyl spinor}}
\end{AnnotatedEquation}
\end{frame}
\end{document}

在此处输入图片描述

还可以进一步改进,但需要实际使用它的用户的输入。

相关内容