Amsmath and mathtools provides two macros to label terms of an equation:

\documentclass{article}

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsfonts}

\newcommand{\E}[3][]{\mathbb{\operatorname{E}}_{#2}#1[#3#1]}
\newcommand{\KL}[2]{D_\mathrm{\operatorname{KL}}[#1\;\|\;#2]}

\begin{document}

\begin{align}
\underbrace{\E{q_\phi(\theta)}{\ln p(\mathcal{D}|\theta)}}_\text{expected likelihood}
-\underbrace{\KL{q_\phi(\theta)}{p(\theta)}}_\text{complexity} \\
\underbracket{\E{q_\phi(\theta)}{\ln p(\mathcal{D}|\theta)}}_\text{expected likelihood}
-\underbracket{\KL{q_\phi(\theta)}{p(\theta)}}_\text{complexity}
\end{align}

\end{document}

underbrace and underbracket

I'd like to get this behavior, except that the brace or bracket is just a thick straight line. Is this possible using these or other packages?

  • 4
    It could get confusing, if misconstrued for a vinculum – Steven B. Segletes Aug 20 at 13:57
  • 2
    Know what I mean? Vinc-vinc, nudge nudge. – Steven B. Segletes Aug 20 at 16:31
up vote 12 down vote accepted

Manipulating the <rule thickness> and <bracket height> in

\underbracket[<rule thickness>][<bracket height>]{<arg>}

suffices. Note that I removed \mathbb{...}, simplified \mathrm{KL}, and changed \;\|\; to \mathrel{\Vert}. You may also want to use \mid instead of | in \ln p(\mathcal{D}|\theta).

\documentclass{article}

%\usepackage{amsmath}
\usepackage{mathtools}
%\usepackage{amsfonts}% not needed since I removed `\mathbb'

\newcommand{\E}[3][]{\operatorname{E}_{#2}#1[#3#1]}
\newcommand{\KL}[2]{D_{\mathrm{KL}}[#1\mathrel{\Vert}#2]}% Put `\mathrm{KL}' in braces. Thanks, @egreg!

\begin{document}

\begin{align}
\underbrace{\E{q_\phi(\theta)}{\ln p(\mathcal{D}|\theta)}}_\text{expected likelihood}
-\underbrace{\KL{q_\phi(\theta)}{p(\theta)}}_\text{complexity} \\
\underbracket{\E{q_\phi(\theta)}{\ln p(\mathcal{D}|\theta)}}_\text{expected likelihood}
-\underbracket{\KL{q_\phi(\theta)}{p(\theta)}}_\text{complexity} \\
\underbracket[0.27778ex][0pt]{\E{q_\phi(\theta)}{\ln p(\mathcal{D}|\theta)}}_\text{expected likelihood}
-\underbracket[0.27778ex][0pt]{\KL{q_\phi(\theta)}{p(\theta)}}_\text{complexity}
\end{align}

\end{document}

underline

I agree with @StevenB.Segletes: This looks rather confusing. Are you dividing the expectation by “expected likelihood”, and dividing the information/entropy by “complexity”? Even with the thick rules, the expressions in Eq. (3) appear to be (poorly typed) fractions at first glance.

  • 1
    I'm not gonna even post my answer, because this one is so nice and straightforward. – Steven B. Segletes Aug 20 at 14:10

You can realize it with other methods than \underbracket:

\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}

\newcommand{\E}[3][]{\operatorname{\mathbb{E}}_{#2}#1[#3#1]}
\newcommand{\KL}[2]{D_{\mathrm{KL}}[#1\dmid#2]}
\newcommand{\dmid}{\parallel} % a semantic alias

\newcommand{\explain}[2]{{%
  \vtop{\offinterlineskip\halign{\hfil##\hfil\cr
    $\displaystyle{#1}$\cr
    \noalign{\vskip1pt\hrule height 1pt\vskip1pt}
    {\scriptsize\strut#2}\cr
  }}%
}}

\begin{document}

\begin{equation}
\explain{\E{q_\phi(\theta)}{\ln p(\mathcal{D}\mid\theta)}}
        {expected likelihood}
-\explain{\KL{q_\phi(\theta)}{p(\theta)}\vphantom{\E{q_\phi(\theta)}{}}}
         {complexity}
\end{equation}

\end{document}

I've fixed the definition of \E to have \operatorname and \mathbb switched. There is no need to do \mathrm{\operatorname{KL}} and an additional pair of braces is recommended: D_{\mathrm{KL}} is correct.

A \vphantom will make the underlines align. The | should be \mid.

enter image description here

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.