# Align equations to start in the same position

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

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:

\begin{align*}
\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
\end{align*}


but unfortunately, I get:

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

Tags :

#### 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:

\documentclass{article}

\usepackage{eqparbox,xparse,amsmath,amsfonts}

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
% \eqmathbox[<tag>][<align>]{[itex]}
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
\IfValueTF{#1}
{\def\[email protected]##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
{\def\[email protected]##1##2{\eqmakebox{$##1##2$}}}
\mathpalette\[email protected]{#3}
}
\makeatother

\begin{document}

\begin{align*}
\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
\end{align*}

\end{document}

Werner
September 11, 2019 16:22 PM