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?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityThe \\
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?
\\
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.
May 13, 2012 at 7: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.
May 12, 2012 at 13:35
\@ifstar{\let \reserved@e \vadjust \let \reserved@f \nobreak \@xnewline}
(the exact \\*
code from latex.ltx
) if @Uiy is interested :)
\` 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
May 13, 2012 at 7:35
\` signals the end of the line (in text) as well as the end of a row (in environments like
tabular,
align, etc.). Never seen or used a
\*`.\\*
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*\\*
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.