6

This question already has an answer here:

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.

marked as duplicate by Mico equations Oct 21 '17 at 8:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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 '17 at 6:20
8

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}
  • 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 '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
  • 2
    @Sebastiano - Instead of writing <url>, write [this answer](<url>). (It's an example of "markdown code".) – Mico Oct 21 '17 at 10:15
  • 1
    @MIco Thanksssssssssssssssssssssssssssssss. Great!!! – Sebastiano Oct 21 '17 at 10:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.