3

I am trying to write the below formula in latex, but as you can see the subscript for sigma is not aligned with the one for mu. This is caused by the square in alpha. How can I align them?

enter image description here

UPDATE: the formula is in inline mode, like this

$q_{\phi}(z|x_i) \sim \mathcal{N}(\mathbf{\mu}_{z|x_i}, \mathbf{\sigma}_{z|x_i}^2\mathbf{I})$

UPDATE2: thanks to the link sent by @AndrewSwann, the vphantom command makes the trick!

$q_{\phi}(z|x_i) \sim \mathcal{N}(\mathbf{\mu}_{z|x_i}^{\vphantom{2}}, \mathbf{\sigma}_{z|x_i}^2\mathbf{I})$

enter image description here

Thanks

  • easiest seems to be to add an empty superscript to the µ – remco Apr 12 '18 at 07:50
  • This is tex's standard placement. See e.g. https://tex.stackexchange.com/q/123945/15925 for a work around. See also https://tex.stackexchange.com/q/88362/15925 for more discussion. – Andrew Swann Apr 12 '18 at 07:55
  • @remco it aligs the subscripts, but it also adds a small apostopre at the top of mu – user1571823 Apr 12 '18 at 07:56
  • Is there a special meaning in the fact that z and x_i are normal weight in the left hand side and boldface in the right hand side? Can you please show the code you're using for that formula? – egreg Apr 12 '18 at 07:56
  • @user1571823 Not for me, using either PdfLatex or LuaLatex, with or without amsmath loaded. But as we don't have your code, hard to say more. – remco Apr 12 '18 at 07:59

2 Answers2

2

If you want a boldface mu, the command \mathbf is useless (and you get a normal weight mu, as you see).

A boldface mu can be obtained with \bm{\mu}. As said in the comments, sigma should not be boldface.

For aligning the subscripts, add an empty superscript.

\documentclass{article}
\usepackage{amsmath}
\usepackage{bm}

\begin{document}

$q_{\phi}(z\mid x_i) \sim
\mathcal{N}(\bm{\mu}^{}_{z\mid x_i}, \sigma_{z\mid x_i}^2\mathbf{I})$

\end{document}

enter image description here

egreg
  • 1,121,712
  • I'm pretty sure the \sigma^2 item on the right-hand side should not be rendered in bold. The full expression on the right is about a multivariate normal random variable with mean vector \mu and "scalar" (more precisely: diagonal, with all diagonal elements equal to one another) variance-covariance matrix. Thus, it's correct to write \mathbf{I} to denote the identity matrix, but \sigma should not be rendered in bold as well. – Mico Apr 12 '18 at 08:21
  • @Mico nice catch! i'll remove the bold command. Thanks – user1571823 Apr 12 '18 at 08:23
0

Just for completeness, here's a solution that employs LuaLaTeX and the unicode-math package.

Note that with unicode-math loaded, it's not necessary to load the bm package as well. The \symbf macro can be applied to both \mu and I.

enter image description here

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{unicode-math}
\begin{document}
\[
q_{\phi}(z\mid x_i) \sim \mathcal{N}
(\symbf{\mu}^{}_{z\mid x_i}, 
\sigma_{z\mid x_i}^2\symbf{I})
\]
\end{document}
Mico
  • 506,678