How to center a multiline equation? [duplicate]

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{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{aligned}



When I use center, I get this error:

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


Thanks for any help.

marked as duplicate by Mico equations StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Oct 21 '17 at 8:23

• center is a text-mode environment. Don't use it inside math mode. (The material inside a center env. is taken to be text-mode material by default.) – Mico Oct 21 '17 at 6:20

Use a gathered environment inside the equation environment:

\documentclass{article}
\usepackage{amsmath} % for "gathered" env.
\begin{document}
$$\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{document}

• I vote your question Mico. JaySf, there is a similar question at the link: tex.stackexchange.com/questions/9268/centering-split-equation. – Sebastiano Oct 21 '17 at 7:42
• See, in particular, this answer to the query identified by @Sebastiano. – Mico Oct 21 '17 at 8:23
• @Mico How do to create a direct link of the answer (see this answer), please? Thanks a lot. – Sebastiano Oct 21 '17 at 9:01
• @Sebastiano - Instead of writing <url>, write [this answer](<url>). (It's an example of "markdown code".) – Mico Oct 21 '17 at 10:15
• @MIco Thanksssssssssssssssssssssssssssssss. Great!!! – Sebastiano Oct 21 '17 at 10:29