# How to typeset a system of equations with multiple alignment points

I'm aware of how to align a system of equations on the = sign (or other single alignment point), but I'd like to align a system at multiple points so that each variable stays in its own "column" so to speak. This is especially an issue if some variables have a 0 coefficient in some equations.

I'd like to extend this idea to typesetting a linear programming problem such as this:

I use \alignat in LaTeX for this, but am trying to write more in Mathematica and would like to learn how to do it there.

Thanks!

• Some ideas here. Commented Nov 27, 2013 at 20:22
• I think at some level you'll have to use Grid. Note it can be entered in any cell directly with <kbd>Ctrl</kbd>+<kbd>,</kbd>, etc. See the link. Commented Nov 27, 2013 at 21:47
• fyi, question is posted at community. community.wolfram.com/groups/-/m/t/161293?p_p_auth=jAPxO1LC please do not post in two places without pointing links to each others. Someone might end up wasting their time trying to solve something already solved or ask a question already answered at the other place. Commented Nov 27, 2013 at 22:09

Since this is for typesetting equations in text cells rather than for input the way I would tackle this problem is not particularly elegant but what I would do is start with a set of equations with all terms present, e.g.

I would then edit to make some of the terms invisible

After selecting parts of your equation go to the option inspector and find ShowContents

Now set that to False:

The continue this process throughout the set of equations:

You could also set this up programmatically using Invisible to return a cell with all this in it but for typesetting in text cells I think this is the more straight forward method.

Here is an example taking LaTeX code for an array (similar to \alignat). This example is far from a generalized way to take LaTeX skills and translate them into good typeset in Mathematica, but in this case it turns out to be pretty effective.

First build the LaTeX code for an array inside quotes (double up on the backslashes):

tex=
"\$\\begin{array}{llllllllll} 2x_1 & -3x_2 & -5x_3 & -4 x_4 & -s_1 & & & +a_1 & & & =20\\\\ 7x_1 & +2x_2 & +6x_3 & -2 x_4 & & +s_2 & & & & & =35\\\\ 4x_1 & +5x_2 & -3x_3 & -2 x_4 & & & -s_3 & & & +a_3 & =15\\\\ \\end{array} \$";


Then evaluate:

ToExpression[tex, TeXForm][[1]]
Grid[%]


There are two outputs, the latter being the desirable one:

A block of LaTeX code inside Mathematica code did not work so well in this post, and that is why I broke it into two pieces. The Grid[ ] function is giving the output without the undesirable matrix brackets.