19

I'm trying to knit a document that has an equation in it and I would like the equation to respect linebreaks. This works fine when I knit to HTML but does not when I knit to pdf.

$$ 
x_1 - ? +\\
x_2 - ? +\\
x_3 - ? +\\
$$

I've also tried \newline and even \hfill \break. I also tried the different latex engines listed on the RMarkdown cheat sheet at RStudio.

1 Answer 1

17

Use Latex code:

\begin{aligned}
x_1 - ? + \\
x_2 - ? + \\
x_3 - ? + 
\end{aligned}

If you do not want a numbered equation, use

\begin{aligned}
x_1 - ? + \nonumber \\
x_2 - ? + \nonumber \\
x_3 - ? + \nonumber
\end{aligned}

This works in HTML and PDF.

2
  • 4
    If you get Package amsmath Error: \begin{aligned} allowed only in math mode. surround the above with \begin{math}...\end{math}
    – Adam_G
    Mar 20, 2019 at 23:37
  • What if I do want an equation number?
    – Adam_G
    Mar 20, 2019 at 23:38

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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