Align equations to start in the same position

by Shani Gamrian   Last Updated September 11, 2019 16:23 PM

I have a list of equations and I want them to be centered and aligned to the beginning of the equation and by the equal sign. This is what I tried so far:

\mathcal{L}_{a2c} &= \mathbb{E}_{s_t,a_t\sim\pi_{\theta}}[\mathcal{L}_{a2c_{policy}} + \frac{1}{2}\mathcal{L}_{a2c_{value}}]\\
\mathcal{L}_{a2c_{policy}} &= -\log{\pi_{\theta}(a_t|s_t)}(V_t^n-V_\theta(s_t)) - \alpha\mathcal{H}_t^{\pi_\theta}\\
\mathcal{L}_{a2c_{value}} &= {(V_t^n-V_\theta(s_t))}^2 

but unfortunately, I get:

enter image description here

As the image shows, the equations are aligned by "=" but start in different positions.

Answers 1

One option is to place each of the left-hand sides of te equations in equally-sized boxes, and <align> each element to the left. \eqmathbox[LHS][l]{<lhs>}, as defined below, will help with that:

enter image description here



% \eqmathbox[<tag>][<align>]{<math>}
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%


  \eqmathbox[LHS][l]{\mathcal{L}_{a2c}} &= 
    \mathbb{E}_{s_t, a_t \sim \pi_{\theta}}[\mathcal{L}_{a2c_{\text{policy}}} + \tfrac{1}{2}\mathcal{L}_{a2c_{\text{value}}}] \\
  \eqmathbox[LHS][l]{\mathcal{L}_{a2c_{\text{policy}}}} &= 
    -\log{\pi_{\theta}(a_t|s_t)}(V_t^n - V_\theta(s_t)) - \alpha\mathcal{H}_t^{\pi_\theta} \\
  \eqmathbox[LHS][l]{\mathcal{L}_{a2c_{\text{value}}}} &= {(V_t^n - V_\theta(s_t))}^2 

September 11, 2019 16:22 PM

Related Questions

Updated June 15, 2017 19:23 PM

Updated May 14, 2015 23:10 PM

Updated September 02, 2019 17:23 PM

Updated February 17, 2018 20:23 PM

Updated July 22, 2019 12:23 PM