How can I auto-number math equations in RMarkdown?

Viewed 18890
$$
r  = \frac{1}{n-1} \sum_{i=1}^{n} \frac{(X_i - \bar{X})(Y_i - \bar{Y})}{S_xS_y}
$$

The rendered equation is not numbered. Using \begin{aligned} and \end{aligned} generates an error.

I am also using knitr in RStudio, knitting to PDF using pandoc and xelatex engine.

Thank you.

2 Answers

As pointed out amsmath is already in the default template, so you can invoke the equation environment

\begin{equation}
y = mx+b
\end{equation}

This will automatically number equations in order of use. To use another character, say *,

\begin{equation}
\tag{*}
y = ax^2 + bx + c
\end{equation}

To leave equation unmarked simply leave tag{} blank.

For differences between align and equation see this answer

Try align not aligned

\begin{align}
    r  = \frac{1}{n-1} \sum_{i=1}^{n} \frac{(X_i - \bar{X})(Y_i - \bar{Y})}{S_xS_y}
\end{align}
Related