Reputation: 464
I've tried to searching online how to align my equation properly, but it still looks like right aligned rather than all the equal signs are aligned, can you help? The below is my code in rmarkdown.
$$
\begin{aligned}
l(\theta_1,\theta_2,\sigma^2)
=-\frac{1}{2}nlog(2\pi)-nlog\sigma-\frac{1}{2\sigma^2}\sum_{i=1}^{n}(y_i-\mu)^2\\
=-\frac{1}{2}nlog(2\pi)-nlog\sigma-\frac{1}{2\sigma^2}\sum_{i=1}^{n}(y_i-\frac{\theta_1x_i}{\theta_2+x_i})^2
\end{aligned}
$$
And the result looks to be right aligned rather than all the equal signs are aligned (see below).
Result
Upvotes: 4
Views: 2295
Reputation: 464
As suggested by one of the comments, & sign needs to be used at where I want it to align, and please see below solution. Edit: As suggested by another comment, log needs to be upright in the math equation and should use \log instead. And \left(
, \right)
is used to make sure the brackets are stretched
$$
\begin{aligned}
l(\theta_1,\theta_2,\sigma^2)
&=-\frac{1}{2}n\log(2\pi)-n\log\sigma-\frac{1}{2\sigma^2}\sum_{i=1}^{n}(y_i-\mu)^2\\
&=-\frac{1}{2}n\log(2\pi)-n\log\sigma-\frac{1}{2\sigma^2}\sum_{i=1}^{n}\left(y_i-\frac{\theta_1x_i}{\theta_2+x_i}\right)^2
\end{aligned}
$$
Upvotes: 3