2

I have already read the posts detailing how to create text that does not take up any space. My question is if I am doing it correctly in this instance.

\documentclass{article}

\usepackage{mathtools}

\newcommand{\n}{\makebox[0pt][r]{$-$}}

\begin{document}
Not using my custom command
\begin{alignat*}{3}
  a_1 & {}-{} & a_2 & {}={} & -3\\
      && a_2 & {}={} & 8\\
      && - a_2 & {}={} & 8
\end{alignat*}

Using my custom command
\begin{alignat*}{3}
  a_1 & {}-{} & a_2 & {}={} & -3\\
      && a_2 & {}={} & 8\\
      && \n a_2 & {}={} & 8
\end{alignat*}
\end{document}

The command \n seems a bit hacky to me, so I was wondering if there is a better resolution to my problem.

3 Answers3

2

Your definition is not really hacky. You can define it a bit simpler using \llap:

\newcommand\n{\llap{$-$}}

\llap and \rlap are essentially the same as \makebox[0pt][r] and \makebox[0pt][l], respectively.

gernot
  • 49,614
  • 1
    I usually discourage using \llap and \rlap. They can have unexpected effects, which \makebox hasn't. – egreg Jan 29 '17 at 00:31
  • And \mathllap (since mathtools is loaded, which would simplify the definition of the command)? – Bernard Jan 29 '17 at 00:40
2

There are better ways: the package systeme and autoaligne. The former has a simpler syntax, the latter is more powerful, but also a bit more difficult when there are missing terms.

\documentclass{article}

\usepackage{autoaligne}
\usepackage{systeme}
\usepackage{regexpatch}

% see http://tex.stackexchange.com/questions/247070/
\makeatletter
\xpatchcmd{\SYS@makesyspreamble@i}
  {$##$\hfil\null}% left alignment
  {\hfil$##$\null}% right alignment
  {}{}
\makeatother

\begin{document}
\[
\sysdelim..
\systeme{
  a_1 - a_2 = -3,
  a_2 = 8,
 -a_2= -8
}
\]

\[
\autoaligne[dd]{%
a_1-a_2=-3 \\%
+a_2=8 \\
-a_2=-8
}
\]

\end{document}

enter image description here

egreg
  • 1,121,712
2

A correct usage of alignat makes things much simpler. Remember that n alignment groups require 2n – 1 ampersands. Actually, here, 2 groups are enough:

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{alignat*}{2}
  a_1- a_2 &={} & -3 & \\
       a_2 &= & 8 & \\
       - a_2 & = & 8 & %
\end{alignat*}

\end{document} 

enter image description here

Bernard
  • 271,350