As far as I know, \\ and \newline both insert a new line. But they do not have an identical expansion and tracing shows they do not execute the same commands, so what is their difference?
- 2,307
1 Answers
From a usage point-of-view, there is a difference between \\ and \newline:
-
Tells LaTeX to start a new line. This command has a starred version and takes an optional parameter:
\\*: Similar to\\but also tells LaTeX not to start a new page after the line by issuing a\nobreak.\\[<len>]: This specifies the vertical space<len>to be inserted before the next line. Can also be negative.
The above two can also be mixed. That is, using both a starred + optional argument combination
\\*[<len>]. -
Same as
\\, but does not take a star.
From a technical point of view (in latex.ltx), these commands are defined as follows, justifying the similarity between \\ (unstarred and without optional argument) and \newline:
\DeclareRobustCommand\\{%
\let \reserved@e \relax
\let \reserved@f \relax
\@ifstar{\let \reserved@e \vadjust \let \reserved@f \nobreak \@xnewline}%
\@xnewline}
\expandafter\let\expandafter\@normalcr
\csname\expandafter\@gobble\string\\ \endcsname
\DeclareRobustCommand\newline{\@normalcr\relax}
LaTeX also redefines \\ to mean other things depending on the environment(s) you use. For example, within an array or tabular environment, the commonly-used \\ has a slightly different meaning to when it is used in regular text.
- 7,143
- 603,163
-
46Note that \ will be redefined by some commands like
\centeringwhile\newlinewon't. For that reason using\newlinewith\centeringwill give undesired results. – Aug 31 '11 at 07:15 -
2
-
42For someone who is new to Latex, your answer reads as: "From a usage POV, there is a difference between A and B: A does something, and B is similar to A. From a technical POV: [Don't understand a word]". Maybe you could add an example of different behavior in common text formatting situations? – Bananach Nov 01 '15 at 10:31
-
10I don't understand the answer. "\ tells ...., \newline Similar to \". So is there a difference between the two or not? What's the difference? Is there an example where the two commands can give different results? – Nicola Gigante Feb 14 '17 at 12:51
-
3@gigabytes: As mentioned in comment,
\centeringwould be one case where\\and\newlinewould yield different results. See this paste and its accompanying output. – Werner Feb 14 '17 at 16:38 -
1I think the point of "similar to
\\" is that it's not starred and not using the optional argument. So a regular\\would be similar to\newline, but\\*and\\[length]would not be similar. – Teepeemm Nov 20 '21 at 02:22 -
1I am gonna be franc: an answer that is meant to explain the difference between A and B, talks about what A does and says that B "is similar" to A is not an answer. Everyone landing here knows that they are similar, but they wanna know the difference. Your answer is merely stating the obvious. Having that said, seeing the technical part provided, I have confidence that you are able to explain the actual differences and would be very keen and grateful to read that. – Mayou36 Sep 05 '22 at 11:04
-
1@Mayou36: What you're missing here is subtle.
\newlineis similar to\\in the sense that it calls\\without the*(optional) or[<len>]optional arguments. Instead, it's similar to\\\relax. – Werner Sep 06 '22 at 07:26 -
1@Werner perfect! But let me claim that not I am missing it, but the answer is missing this. Most notably, "similar" or "same except"? Similar really should not be used here, we're all aware that it's similar. I'd expect to see that "they are the same except the following differences. From your answer, is
\newlinethe same as\\without any arguments? It's "similar" according to the answer, but what does that mean? – Mayou36 Sep 06 '22 at 07:31
\newlineis defined as the normal (i.e., without optional argument and non-starred) version of \. – Gonzalo Medina Aug 30 '11 at 22:58latex.ltx1,\DeclareRobustCommand\newline{\@normalcr\relax}whereexpandafter\let\expandafter\@normalcr \csname\expandafter\@gobble\string\\ \endcsname. – Werner Aug 30 '11 at 23:28\newlinemark the division between paragraphs? – Someone Dec 16 '20 at 15:29