![放置在 tikz 矩形中的方程元素的移位](https://linux22.com/image/325987/%E6%94%BE%E7%BD%AE%E5%9C%A8%20tikz%20%E7%9F%A9%E5%BD%A2%E4%B8%AD%E7%9A%84%E6%96%B9%E7%A8%8B%E5%85%83%E7%B4%A0%E7%9A%84%E7%A7%BB%E4%BD%8D.png)
我想定义新命令来最小化以下代码:
\documentclass{beamer}
\usepackage{mathtools,tikz,lmodern, xparse}
\usetikzlibrary{shapes.geometric, arrows, matrix, positioning, shapes.callouts,shadows,shapes,chains, shapes.misc}
\tikzset{>=stealth}
\usepackage{amsmath} %For align environement
\usepackage{color}% to define the next colors
\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
\definecolor{alizarin}{rgb}{0.82, 0.1, 0.26}
\definecolor{white}{rgb}{1.0, 1.0, 1.0}
\definecolor{blue(munsell)}{rgb}{0.0, 0.5, 0.69}
\begin{document}
\begin{frame}{Quantum corrections to gauge interactions}
\begin{align*}
F(\Phi)= \only<1>{\begin{tikzpicture}[remember picture, note/.style={rounded rectangle, fill=blue}]\node[rounded rectangle, draw, fill=blue!20](Alpha){$\alpha$};
\end{tikzpicture}}\only<2->{\alpha} X
+\only<2>{\begin{tikzpicture}[remember picture, note/.style={rounded rectangle, fill=blue}]\node[rounded rectangle, draw, fill=blue!20](gPhi){$g(\Phi)$};
\end{tikzpicture}}\only<1,3->{g(\Phi)}
\end{align*}
\begin{tikzpicture}[remember picture,
note/.style={rectangle callout,rounded corners, fill=blue}]
\only<1>{\node [note=blue!50, opacity=.5, overlay,
callout absolute pointer={(Alpha.south)}] at (4,-0.3) {CommentI};}
\only<2>{\node [note=blue!50, opacity=.5, overlay,
callout absolute pointer={(gPhi.south)}] at (7,-0.3) {CommentII};}
\end{tikzpicture}
\end{frame}
\end{document}
我试过 :
\documentclass{beamer}
\usepackage{mathtools,tikz,lmodern, xparse}
\usetikzlibrary{shapes.geometric, arrows, matrix, positioning, shapes.callouts,shadows,shapes,chains, shapes.misc}
\tikzset{>=stealth}
\usepackage{amsmath} %For align environement
\usepackage{color}% to define the next colors
\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
\definecolor{alizarin}{rgb}{0.82, 0.1, 0.26}
\definecolor{white}{rgb}{1.0, 1.0, 1.0}
\definecolor{blue(munsell)}{rgb}{0.0, 0.5, 0.69}
\NewDocumentCommand{\rect}{ m m m m m}{\begin{tikzpicture}[remember picture, note/.style={rounded rectangle,rounded corners}]
\node[rounded rectangle, draw, fill=#1!#2](#3){#4};\end{tikzpicture}}
\newcommand{\mycallout}[9]{\begin{tikzpicture}[remember picture, note/.style={rectangle callout,rounded corners}]
\node [note=#3!#4, opacity=.5, overlay,
callout absolute pointer={(#5)}] at (#7,#8) {#9};
\end{tikzpicture}}
\begin{document}
\begin{frame}{Quantum corrections to gauge interactions}
\begin{align*}
F(\Phi)= \only<1>{\rect{blue}{20}{Alpha}{$\alpha$}}\only<2->{\alpha} X
+\only<2>{\rect{blue}{20}{gPhi}{$g(\Phi)$}}\only<1,3->{g(\Phi)}
\end{align*}
\only<1>{\mycallout{blue}{50}{Alpha.south}{4}{0.3} {CommentI}}
\only<2>{\mycallout{blue}{50}{gPhi.south}{7}{-0.3} {CommentII}}
\end{frame}
\end{document}
但它给了我错误File ended while scanning use of \frame.
。我想要修复的另一个问题是由于 tikz 框导致的$\alpha$
和的偏移。${g(\Phi)}$
答案1
我设法修复并优化了你的第一个例子,看看在这之后你是否仍然需要在第二个例子中定义新命令:
\documentclass{beamer}
\usepackage{mathtools,tikz,lmodern, xparse}
\usetikzlibrary{%arrows, chains, matrix,
positioning,
%shadows,
shapes, shapes.callouts,
%shapes.geometric,
%shapes.misc
}
\tikzset{>=stealth,
note/.style={rectangle callout,
callout absolute pointer={#1},
rounded corners, draw, fill=blue!20,
%, fill opacity=.5 %<-- is this necessary?
}
}
\usepackage{amsmath} %For align environement
%\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
%\definecolor{alizarin}{rgb}{0.82, 0.1, 0.26}
%\definecolor{white}{rgb}{1.0, 1.0, 1.0}
%\definecolor{blue(munsell)}{rgb}{0.0, 0.5, 0.69}
\newcommand{\rect}[2]{%
\tikz[remember picture,baseline=-0.5ex]
\node[name=#1,rounded corners, draw, fill=blue!20] {#2};}
\begin{document}
\begin{frame}{Quantum corrections to gauge interactions}
\begin{align*}
F(\Phi)= \only<1>{\rect{Alpha}{$\alpha$}}
\only<2->{\alpha} X +
\only<2>{\rect{gPhi}{$g(\Phi)$};}
\only<3->{g(\Phi)}
\end{align*}
\begin{tikzpicture}[remember picture,overlay,
node distance=7mm and 1mm]
\only<1>{\node [note=(Alpha.south),
below left= of Alpha]
{Comment I};}
\only<2>{\node [note=(gPhi.south),
below right= of gPhi]
{Comment II};}
\end{tikzpicture}
\end{frame}
\end{document}
编辑(1):我添加了newcommand
输入方程式的功能rect
。
编辑(2): newcommand
用于输入mycall
方程式的注释:
\newcommand{\mycallout}[4]{%
\tikz[remember picture,overlay,
node distance=7mm and 1mm]{%
\node [note=(#1.#2),
below #3= of #1]
{#4};} }
并根据您的情况如下使用:
\only<1>{\mycallout{Alpha}{south}{left}{Comment I}}
\only<2>{\mycallout{gPhi}{south}{right}{Comment II}}
正如我所见,它并没有使代码变得更短。