1

I have been using \\ to start a new line in an align block:

\documentclass[12pt, a4paper, twoside, titlepage]{article}

\usepackage{amsmath}

\documentclass[12pt, a4paper, twoside, titlepage]{article}

\usepackage{amsmath}

\begin{document}

  \begin{align}
    &J(1)=                                        & \text{Cost}\\
    &\sum\limits_{i=1}^{m} (h_\Theta(x^i)-y^i)^2= & \text{Cost}\\
    &\sum\limits_{i=1}^{3} (\Theta_1(x^i)-y^i)^2= & \text{Cost}\\
    &\frac{1}{3}((1-1)^2+(2-2)^2+(3-3)^2)=        & \text{Cost}\\
    &\frac{1}{3}(0+0+0)=                          & \text{Cost}\\
    &0
  \end{align}

\end{document}

I've also seen this mark used in other code snippets like "How to align a set of multiline equations".

I am trying to write good Latex. However, I did not find any reference as to whether this newline mark is a good practice within an align block. Furthermore, some answers (like "Aligned equations in LaTeX") use a single blackslash (\). This seem to have the same effect, but does not work for me.

What's the right way to start a new line in an aligned block?

  • 4
    The single backslash is a corruption by the system, it should be and originally was double. Double backslash is fine within align, the right way to do it in fact – Au101 Mar 20 '17 at 21:58
  • 2
    Some posts on the site have been mangled by an unspecified bug turning \\<newline> into a single backslash with no newline. We're trying to fix them, but they're quite a large number. If you find a doubtful one, please, make a comment at https://tex.meta.stackexchange.com/questions/7168/double-backslashes-disappear-from-code – egreg Mar 20 '17 at 21:58
  • Thanks. Will do. So \\ is the right answer? – Adam Matan Mar 20 '17 at 22:03
  • 1
    @AdamMatan : you need to use two adjacent backslashes, \ (hope that prints correctly). – Herb Schulz Mar 21 '17 at 00:34
  • 1
    To be clear \\ is the right answer. Unfortunately the in-line markdown does funny things with backslashes, because the \ is an escape character – Au101 Mar 21 '17 at 03:25
  • If someone likes to post it as an answer I'll be happy to accept – Adam Matan Mar 21 '17 at 05:26
  • 1
    Note that packages typically have documentation (writing texdoc <packagename> in a terminal is often the easiest way of finding it), so if you look in amsmath's docs, you'll see that \\ is the way to go. @Au101 can write up an answer I suppose. – Torbjørn T. Mar 21 '17 at 19:33
  • @AdamMatan "I actually typed two..." Yes I know =) What happened is the second backslash escaped the backtick and that's why you ended up with what you did, the correct input is double backtick double backslash double backtick: \\ but with no spaces: \\ I just wanted to make it absolutely clear =) – Au101 Mar 21 '17 at 19:38
  • @TorbjørnT. I could but I didn't really say much in the comments. You're welcome to it, you'll be able to add more of interest with texdoc and stuff =) – Au101 Mar 21 '17 at 19:39
  • @Au101 I was tempted to close as OT because the OP was confused by the double backslash bug of the site, and I don't really feel like answering. Nothing prevents you from mentioning documentation in an answer though. – Torbjørn T. Mar 21 '17 at 19:45

0 Answers0