Writing an Equation wirh Multiple =, -, + in Multiple Lines

I have this equation

\documentclass{article}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{breqn}
\usepackage{amsmath}
\usepackage{comment}
\usepackage{xfrac}

$$\begin{split} g(z; \mu, b) & = KL(\widetilde{p}(z^{(1)}) \vert \vert \widetilde{q}(z^{(1)}))\\ & = \int_{z}\widetilde{p}(z^{(1)}) \log (\frac{\widetilde{p}(z^{(1)})}{\widetilde{q}(z^{(1)})}) dz \\ & = \int_{z} \widetilde{p}(z^{(1)}) \log (\widetilde{p}(z^{(1)})) dz - \int_{z} \widetilde{p}(z^{(1)}) \log (\widetilde{q}(z^{(1)})) dz \\ & = \int_{z} \widetilde{p}(z^{(1)}) \log (\widetilde{p}(z^{(1)})) dz \\ & = \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)})\log(p(z^{(1)}|z^{(0)})q(z^{(0)})) dz- \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)})\log(\widetilde{q}(z^{(1)}))dz \\ & = \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)}) \log(p(z^{(1)}|z^{(0)})) dz + \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)})\log (q(z^{(0)})) dz \\ & - \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)})\log(\widetilde{q}(z^{(1)}))dz \\ \end{split}$$


When compiling, the - sign (on the last line) is placed directly underneath = sign. I want it to be placed a bit to its right. Is there such a possibility?

I tried with \begin{dmath} as well.

\begin{dmath}
g(z; \mu, b)
= KL(\widetilde{p}(z^{(1)}) \vert \vert \widetilde{q}(z^{(1)}))
= \int_{z}\widetilde{p}(z^{(1)}) \log (\frac{\widetilde{p}(z^{(1)})}{\widetilde{q}(z^{(1)})}) dz
= \int_{z} \widetilde{p}(z^{(1)}) \log (\widetilde{p}(z^{(1)})) dz - \int_{z} \widetilde{p}(z^{(1)}) \log (\widetilde{q}(z^{(1)})) dz
= \int_{z} \widetilde{p}(z^{(1)}) \log (\widetilde{p}(z^{(1)})) dz
= \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)})\log(p(z^{(1)}|z^{(0)})q(z^{(0)})) dz- \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)})\log(\widetilde{q}(z^{(1)}))dz
= \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)}) \log(p(z^{(1)}|z^{(0)})) dz + \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)})\log (q(z^{(0)})) dz
- \int_{z}p(z^{(1)}|z^{(0)})q(z^{(0)})\log(\widetilde{q}(z^{(1)}))dz

\end{dmath}


but for some reason, it does not compile as it supposed to! I used it one day before and it worked but today it just doesn't!

Any help is immensely appreciated :)

• You should try inserting something like \quad or \qquad just before the -.
– Werner
Commented Jun 9, 2021 at 15:33

You could change & to &\qquad for lines that need to be indented a bit.
\documentclass{article}
$$\begin{split} g(z; \mu, b) & = KL(\tilde{p}(z^{(1)}) \,\Vert\, \tilde{q}(z^{(1)}))\\ & = \int_{z}\tilde{p}(z^{(1)}) \log \Bigl(\frac{\tilde{p}(z^{(1)})}{\tilde{q}(z^{(1)})}\Bigr)\, dz \\ & = \int_{z} \tilde{p}(z^{(1)}) \log (\tilde{p}(z^{(1)}))\, dz \\ &\qquad - \int_{z} \tilde{p}(z^{(1)}) \log (\tilde{q}(z^{(1)}))\, dz \\ & = \int_{z} \tilde{p}(z^{(1)}) \log (\tilde{p}(z^{(1)}))\, dz \\ & = \int_{z}p(z^{(1)}\mid z^{(0)})q(z^{(0)})\log(p(z^{(1)}\mid z^{(0)})q(z^{(0)}))\, dz \\ &\qquad - \int_{z}p(z^{(1)}\mid z^{(0)})q(z^{(0)})\log(\tilde{q}(z^{(1)}))dz \\ & = \int_{z}p(z^{(1)}\mid z^{(0)})q(z^{(0)}) \log(p(z^{(1)}\mid z^{(0)}))\, dz \\ &\qquad + \int_{z}p(z^{(1)}\mid z^{(0)})q(z^{(0)})\log (q(z^{(0)}))\, dz \\ &\qquad - \int_{z}p(z^{(1)}\mid z^{(0)})q(z^{(0)})\log(\tilde{q}(z^{(1)}))dz \\ \end{split}$$