[Tex/LaTex] How to center a multiline equation?

equationsknitrpandoc

I want to center multi row equationing but all my attemts won't work. I'm working with pandoc/knitr of Rmarkdown. I show you an example:

\begin{equation}
\begin{aligned}
<!-- \begin{center} -->
\label{eq1}
x_1 = 1, x_2 = 1 \\
h(x) = f(-20 + 15 + 17) \\
h(x) = f(12) \approx 1 \\
<!-- \end{center} -->
\end{aligned}
\end{equation}
    \end{aligned}
\end{equation}

When I use center, I get this error:

! Missing $ inserted.
<inserted text> 
            $
l.100 \begin{center}

Thanks for any help.

Best Answer

Use a gathered environment inside the equation environment:

\documentclass{article}
\usepackage{amsmath} % for "gathered" env.
\begin{document}
\begin{equation}\label{eq1}
  \begin{gathered}
    x_1 = 1, x_2 = 1        \\
    h(x) = f(-20 + 15 + 17) \\
    h(x) = f(12) \approx 1   % no "\\" needed here
  \end{gathered}
\end{equation}
\end{document}
Related Question