17

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.

1
  • 1
    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, 2017 at 6:20

1 Answer 1

28

Use a gathered environment inside the equation environment:

enter image description here

\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}
5
  • 2
    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, 2017 at 7:42
  • See, in particular, this answer to the query identified by @Sebastiano.
    – Mico
    Oct 21, 2017 at 8:23
  • 1
    @Mico How do to create a direct link of the answer (see this answer), please? Thanks a lot.
    – Sebastiano
    Oct 21, 2017 at 9:01
  • 2
    @Sebastiano - Instead of writing <url>, write [this answer](<url>). (It's an example of "markdown code".)
    – Mico
    Oct 21, 2017 at 10:15
  • 2
    @MIco Thanksssssssssssssssssssssssssssssss. Great!!!
    – Sebastiano
    Oct 21, 2017 at 10:29

Not the answer you're looking for? Browse other questions tagged .