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

5
  • easiest seems to be to add an empty superscript to the µ
    – remco
    Commented Apr 12, 2018 at 7:50
  • This is tex's standard placement. See e.g. tex.stackexchange.com/q/123945/15925 for a work around. See also tex.stackexchange.com/q/88362/15925 for more discussion. Commented Apr 12, 2018 at 7:55
  • @remco it aligs the subscripts, but it also adds a small apostopre at the top of mu Commented Apr 12, 2018 at 7: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
    Commented Apr 12, 2018 at 7: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
    Commented Apr 12, 2018 at 7:59

2 Answers 2

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

2
  • 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
    Commented Apr 12, 2018 at 8:21
  • @Mico nice catch! i'll remove the bold command. Thanks Commented Apr 12, 2018 at 8: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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .