I have some code, and when I use \\*, it causes some things to become unaligned, but when I use \\, the alignment is correct.
What's the difference?
I have some code, and when I use \\*, it causes some things to become unaligned, but when I use \\, the alignment is correct.
What's the difference?
The \\ command is one of the most overloaded commands of LaTeX, i.e., its actual definition depends on the place where it is used.
According to the the LaTeX manual by Leslie Lamport (which should be considered the source of truth here) its general definition is
\\ produce an explicit line break (or indicate the end of a row etc)\\* produce line break but do not break page hereEither variant can take an optional argument to add additional space after the line or row. This syntax is supported throughout core LaTeX even in places where it is technically impossible to have a pagebreak (for example inside a tabular) you can still write \\* without getting into a problem.
In core LaTeX the command is supported by environments like array, tabular, tabbing, eqnarray, center, flushleft, flushright, verse, and commands like \shortstack, \author and perhaps others. And of course it is supported in normal paragraph text.
But it does have different internal definitions in most of these places.
In standard LaTeX there can be spaces (or even a linebreak) between \\ and * which can sometimes come as a big surprise.
For this reason amsmath is redefining \\ inside its math environments (like align, etc.) to only recognize a * if it is immediately followed.
Now given that \\ is such a nice short command, other packages have adopted it as well, so you will find probably many more redefinitions of \\ inside other packages. Ideally (assuming that it is used there also for indicating "line/row breaks") all these add-ons should follow the LaTeX example and provide the same syntax, i.e., supporting a * form and one optional argument. However, there is no guarantee that this has been done always. If not, I would suggest to write to the package author and ask for supporting the standard LaTeX syntax fully. After all, if somebody writes a superdupertabular but does this in a way that you can't place the body of a standard tabular unchanged into it, then this is less helpful as it could be.
\\ expanded into something by tex? and when you add the * it gets attached to the end of that expansion which changes it's meaning slightly?
– Uiy
May 12 '12 at 23:18
\\ what happens is that the command explicitly scans for a following * and then for an [ indicating an optional argument. In the process it jumps over spaces which is why you can write \\ * [1cm] and it will still be accepted. Having said that this is for the implementations done by LaTeX core ... as explained this may not be true for third-party packages.
– Frank Mittelbach
May 13 '12 at 07:40
\\* starts a newline but avoids starting a new page, i.e. it is equivalent to \\ immediately followed by \nopagebreak. See What is the difference between \newline and \\? for more details.
(edited to correct \nobreak by \nopagebreak, as suggested by comments below)
\\* is not equivalent to \\\nobreak. \nobreak in that position would be in horizontal mode so would prevent a line break not a page break.
– David Carlisle
May 12 '12 at 13:35
\@ifstar{\let \reserved@e \vadjust \let \reserved@f \nobreak \@xnewline} (the exact \\* code from latex.ltx) if @Uiy is interested :)
– Xavier
May 12 '12 at 23:57
\\ followed by \nopagebreak (not true either but closer) and not followed by \nobreak as the latter is preventing a line break in horizonal mode. So it is not about the internals
– Frank Mittelbach
May 13 '12 at 07:35
\\*often is used to introduce a linebreak, but preventing a page break; however, some environments redefine it, so you have to be more specific about the scenario in which you are using this command. – Gonzalo Medina May 12 '12 at 03:55\\signals the end of the line (in text) as well as the end of a row (in environments liketabular,align, etc.). Never seen or used a\\*. – JohnD May 12 '12 at 03:11\\*somewhere as it solved some problem and used it to solve some other problem then used it again and it caused problems ;) the*, I think gets stuck after \hfill or something so you end up with \hfill* – Uiy May 12 '12 at 03:26