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>]
.
\newline
Similar to \\
.
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.
\nobreak
is defined in plain TeX (and given the same definition in LaTeX) as
\penalty \@M
which is \penalty 10000
which is an infinitely bad place to break (a line if in horizontal mode or a page if in vertical mode).
\nolinebreak
Is a LaTeX command that tests that it is in horizontal mode, and gives an error message if not, and then can give one of 5 different penalty values giving different strengths of hint \nolinebreak[0]
to ... \nolinebreak[4]
4
is the default and gives \@M
the same as \nobreak
. The actual penalties inserted for values 0–4 are set by the class file.
The values are [0]
is penalty 0
, 4
is penalty 10000 and 1–3 are set (in article
class) by
\@lowpenalty 51
\@medpenalty 151
\@highpenalty 301
There is also some code to fix white space so that
a \nolinebreak[0] b
a\nolinebreak[0] b
a \nolinebreak[0]b
each get exactly one word space between a and b if no break happens.
So in the usual case the two commands do the same thing. The LaTeX one takes more time and because of the optional argument testing it used to be fragile (it is robust in LaTeX releases since 2019). So since most LaTeX2e class files use quite low level code you usually see \nobreak
or even just \penalty\@M
in class files but in documents it is better to use the LaTeX form usually for the extra error checking and the interface to standard levels of penalty hint set by the class.
Best Answer
If your
tabular
containsp
-columns, then there is a ambiguity: Does\\
should end a line inside a cell or should it end a tabular row? The use of\newline
and\tabularnewline
make that clear, the first ends the line in a cell, the latter the row of the table.See also
\arraybackslash
of packagearray
that can be used to reset the meaning of\\
to be\tabularnewline
, from the documentation: