Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

enter image description here

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!

share|improve this question
1  
Some ideas here. –  Sjoerd C. de Vries Nov 27 '13 at 20:22
1  
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. –  Michael E2 Nov 27 '13 at 21:47
1  
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. –  Nasser Nov 27 '13 at 22:09

2 Answers 2

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.

enter image description here

I would then edit to make some of the terms invisible

enter image description here

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

enter image description here

Now set that to False:

enter image description here

The continue this process throughout the set of equations:

enter image description here

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.

share|improve this answer

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:

enter image description here

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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