我想在用 hf-tikz 装箱后将解释放在数学下方。我能找到的解决方案是使用 \underbrace,但效果不太好。我正在寻找一种没有括号的类似 underbrace 的对齐方式。有这样的吗?
这是 Beamer 中的一个工作示例
\documentclass[aspectratio=169]{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{mathtools}
\usepackage{hf-tikz}
\begin{document}
\begin{frame}
\frametitle{Text under equation blocks}
\begin{equation*}
\begin{aligned}
a = \onslide<2->\underbrace{ \tikzmarkin{a} \onslide<1-> b \onslide<2-> \tikzmarkend{a}}_{\alert{\text{text1}}} \onslide<1->+ \onslide<3->\underbrace{ \tikzmarkin{b} \onslide<1-> c \onslide<3-> \tikzmarkend{b}}_{\color{brown}{\text{text2}}}
\end{aligned}
\end{equation*}
\end{frame}
\end{document}
答案1
我将使用array
顶部对齐:
\documentclass[aspectratio=169]{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{mathtools}
\usepackage{hf-tikz}
\begin{document}
\begin{frame}
\frametitle{Text under equation blocks}
\[
a =
\onslide<2->%
\begin{array}[t]{@{}c@{}}
\tikzmarkin{a}\onslide<1-> b\onslide<2->\tikzmarkend{a}\\
\scriptstyle\text{\alert{text1}}
\end{array}
\onslide<1->+
\onslide<3->%
\begin{array}[t]{@{}c@{}}
\tikzmarkin{b}\onslide<1-> c\onslide<3->\tikzmarkend{b}\\
\scriptstyle\text{\color{brown}text2}
\end{array}
\]
\end{frame}
\end{document}
轻微错位是由于手动截屏造成的
答案2
使用markings
包的选项可以派生出一个\annotate
命令:
\newcommand{\annotate}[2][]{
\tikz[remember picture,overlay]\node[#1,use marker id] at (0,0){#2};
}
完整示例:
\documentclass[aspectratio=169]{beamer}
\usepackage{lmodern}
\usepackage{mathtools}
\usepackage[beamer,markings]{hf-tikz}% hf-tikz load itself tikz and the calc library
\newcommand{\annotate}[2][]{
\tikz[remember picture,overlay]\node[#1,use marker id] at (0,0){#2};
}
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
\begin{document}
\begin{frame}
\frametitle{Text under equation blocks}
\begin{equation*}
\begin{aligned}
a = \phantom{aaaaa}\tikzmarkin<1->[mark at=0.825]{a}b\tikzmarkend{a}\annotate[visible on=<1->,below,red,font=\scriptsize]{Model Mismatch}
\phantom{aaaaa} +\phantom{Noi} \tikzmarkin<2->[mark at=0.825]{b}c\tikzmarkend{b}\annotate[visible on=<2->,below,brown,font=\scriptsize]{Noise}
\end{aligned}
\end{equation*}
\end{frame}
\end{document}
关键点是:
- 用钥匙标记位置
mark at
(要验证位置标记的位置,您可以结合使用钥匙show markers
); - 在突出显示的变量之间和之后插入一些
phantom
空格,因为注释文本相对于变量来说太大。
结果:
改良版
根据egreg 的评论,这是一个更自动化的解决方案,\mathmakebox
利用mathtools
包。它提供了一个新\tikzmarkaligned
命令,可以根据注释宽度设置空间:
\documentclass[aspectratio=169]{beamer}
\usepackage{lmodern}
\usepackage{mathtools,xparse}
\usepackage[beamer,markings]{hf-tikz}% hf-tikz load itself tikz and the calc library
\newcommand<>{\annotate}[2][]{
\onslide#3{
\tikz[remember picture,overlay]\node[#1,use marker id] at (0,0){#2};
}
}
\newlength{\notewidth}
\newcommand{\setnotewidth}[1]{%
\settowidth{\notewidth}{$#1$}%
}
\newcommand{\mth}[2]{
\setnotewidth{#2}
\mathmakebox[0.355\notewidth]{#1}
}
\NewDocumentCommand{\tikzmarkaligned}{r<> o m m}{
\phantom{\mth{#3}{#4}}
\tikzmarkin<#1>[#2]{#3}#3\tikzmarkend{#3}
\phantom{\mth{#3}{#4}}
}
\begin{document}
\begin{frame}
\frametitle{Text under equation blocks}
\begin{equation*}
\begin{aligned}
a =
\tikzmarkaligned<1->[mark at=0.825]{a}{Model Mismathc}
\annotate<1->[below,red,font=\scriptsize]{Model Mismatch}+
\tikzmarkaligned<2->[mark at=0.825]{b}{Noise}
%\tikzmarkin<2->[mark at=0.825]{b}c\tikzmarkend{b}
\annotate<2->[below,brown,font=\scriptsize]{Noise}
\end{aligned}
\end{equation*}
\end{frame}