# Text below equation with hf-tikz

I would like to put explanation below math after boxing the pieces with hf-tikz. The solution I could find is using \underbrace but it does not look good. I am looking for an underbrace-like alignment without the brace. Is there such a thing?

Here is a working example in 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}

-
Welcome to TeX.SX! –  Papiro Sep 15 '13 at 9:17
Please provide a minimal working example that produces your shown result! That makes it easier for us. –  LaRiFaRi Sep 15 '13 at 9:28

I'd use an array with top alignment:

\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}


The slight misalignment is due to manually taking screen shots

-

Using the markings option of the package one might derive an \annotate command:

\newcommand{\annotate}[2][]{
\tikz[remember picture,overlay]\node[#1,use marker id] at (0,0){#2};
}


A complete example:

\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}


The key points are:

1. mark the positions with the mark at key (to verify where the location is marked you might use in combination the show markers key);
2. insert some phantom space between and after the variable highlighted as the annotation text is too much larger with respect to the variables.

The result:

Improved version

According to egreg's comment, here is a more automatic solution exploiting \mathmakebox from the mathtools package. It provides a new \tikzmarkaligned command which sets the space according to the annotation width:

\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}

-
Nice but clumsy because of the phantoms; by the way, I'd use \hphantom rather than \phantom. Did you try with \mathmakebox (provided by mathtools)? With calc's \widthof it might solve the issue. –  egreg Sep 15 '13 at 10:52
@egreg: yes, this requires some manual work. I will have check \mathmakebox as soon as possible. Thanks for the hint :) –  Claudio Fiandrino Sep 15 '13 at 16:56
Definitely less clumsy. ;-) Unfortunately, I can't upvote twice. –  egreg Sep 19 '13 at 8:15
@egreg: that's because you gave me a nice direction. :) And there's still room for improvements (i.e. not use as \tikzmark identifier the content to be highlighted and provide some mechanism to fine tune the width of the half left and half right part part of the box). That's might be a new feature for the package... –  Claudio Fiandrino Sep 19 '13 at 8:57