4

I'm trying to line up the variables of systems of equations. The following code:

$$\left\\{
\begin{aligned}
&\alpha + 2&\beta + &\gamma & = 0 \\\\
3&\alpha + 7&\beta + 5&\gamma & = 1
\end{aligned}
\right.$$

produces the following image:

enter image description here

I want the Greek letters and the math symbols to be aligned, with appropriate spacing in between coefficients. I've tried using \begin{aligned} \end{aligned} and \begin{array}{ll} \end{array}{ll} as well, but they also don't provide the desired outcome.

Would anyone be kind enough to help me out? Thank you.

4

First of all, do not use $$ ... $$, which is plain TeX, use the LaTeX construct [ ... \].

Second, 4 alignment points require 7 ampersands, not 4: each new column of alignment has to be introduced by an ampersand. So n alignment points require 2n–1 ampersands.

Last: use alignat (or alignedat) to have full control on the spacing between columns of alignment.

Here is a possible code:

\[ \left\{
\begin{alignedat}{4}
&\alpha &{} + 2&\beta + {} & &\gamma & & = 0 \\\\
3&\alpha &{} + 7&\beta + 5 & &\gamma & & = 1
\end{alignedat}

However, using the systeme package makes it simpler to type:

\[ \systeme[\alpha\beta\gamma]{\alpha + 2\beta +\gamma = 0, 3\alpha + 7\beta + 5\gamma = 1} \]

enter image description here

  • I had no idea that $ was plain TeX, thanks! Unfortunately it seems that for the Github Markdown I'm trying to edit, \[ doesn't seem to work... But \begin{alignedat}{4} \end{alignedat} works perfectly! – Seankala Feb 21 at 15:36
  • I've updated with a simpler way to type (the \systeme command from the homonymous package). – Bernard Feb 21 at 15:38
  • 1
    In your first method, the spacing around the = is not correct. – Steven B. Segletes Feb 21 at 15:42
  • 1
    \amsldoc (amsmath documentation) and systeme. Feel free to ask any questions. – Bernard Feb 21 at 16:08
  • 1
    The empty curly braces are there because $+$ (or $-$) are binary operators with a special spacing w.r.t. the elements on the right and on the left. This can be destroyed by an ampersand, and to compensate, one has to add an empty argument, namely {}. For the number of &, maybe I was not clear enough: each column of alignment, but the first, has to be introduced by an &. Inside this column, the alignment point is specified with another &. Check on my code, you should see this rule is respected. Is this clear? – Bernard Feb 21 at 16:26
5

Something like this?

\documentclass{article}
\usepackage{tabstackengine}
\begin{document}
\[
\left\{
\setstackgap{L}{18pt}
\Matrixstack[r]{
\alpha  +& 2\beta +&  \gamma =& 0 \\
3\alpha +& 7\beta +& 5\gamma =& 1
}
\right.
\]
\end{document}

enter image description here

4

Here's a solution that requires only the basic array package. The following code also sets up a custom array-like environment.

enter image description here

\documentclass{article}
\usepackage{array} % for "\newcolumntype" macro
\newcolumntype{C}{>{{}}c<{{}}}
%% set up a little custom enrironment:
\newenvironment{myarray}[1]{%
   \setlength\arraycolsep{0pt}
   \left\{ \begin{array}{#1}}{%
   \end{array} \right.}

\begin{document}
\[
\begin{myarray}{rCrCrCl}
 \alpha &+& 2\beta &+&  \gamma &=& 0 \\
3\alpha &+& 7\beta &+& 5\gamma &=& 1
\end{myarray}
\]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.