TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Whenever I try to use the alignat environment, it doesn't seem to work on my computer! I tried the following simple code (my file had \usepackage{amsmath}):

    \min \quad x_1        & + 2x_2 & + 4x_3 &      &   & \\  
    \text{s.t.} \quad x_1 & + x_2  & + 3x_3 & =    & 5 & \\  
    2x_1                  & + x_2  & + 6x_3 & =    & 8 & \\  
    x_1                   &, x_2   &, x_3   & \geq & 0 & .  

On compilation, I get the following error:

    ! Missing # inserted in alignment preamble.  <to be read again>   
               \crcr l.114   \end{alignat}

Any ideas why this might be?

share|improve this question
That code works for me. Does it work for you if you just use that in an otherwise empty document? – TH. Aug 18 '10 at 3:51

It's been a while, and you probably fixed your problem by now. But since another question involving alignat (well, my answer involves it anyway) came up, and this question scores quite high for the google query latex alignat, I wanted to make sure that there's more information here....

I'm not sure what you are trying to align. I'm assuming you want the x_i's aligned, in which case the correct solution would be

\min \quad x_1& {}+{}& 2x_2& {}+{}& 4x_3& \\
\text{s.t.} \quad x_1& {}+{}&x_2&{}+{} & 3x_3&=5\\
2x_1& {}+{}& x_2& {}+{}&6x_3& = 8\\
x_1&, &x_2&, &x_3& \geq 0 .

which produces:

alt text

while your code produces:

alt text

As you see, you need to put alignment characters between the columns to be aligned, not only inside the columns.

share|improve this answer
There is a lot of missing white space in your example. You should perhaps write {}+{} instead of +? – Jukka Suomela Oct 18 '10 at 19:45
Thanks Jukka! Fixed it. – Yossi Farjoun Oct 18 '10 at 20:33
Explaining why the {}+{} are needed: (I think) LaTeX typesets the spaces around binary operators differently than it does around unitary ones. we would want +r to have less space between the two characters than b+r. And since each column in alignat is typeset separately, it doesn't "see" that the +'s are binary operators. – Yossi Farjoun Oct 18 '10 at 20:35

Your code also compiles for me, and as Lev suggested constructing a minimal example will really help to narrow down where your problem lies, but I was able to generate a similar error to what you have by incorrectly using the tabular environment inside the alignat environment.

For example,


results in the error

! Missing # inserted in alignment preamble.
<to be read again> 
l.9 \end{alignat}

Since the l.9 and l.114 just refer to line numbers in the code, the main difference is that my error includes \cr where yours says \crcr.

I can solve my alignment preamble error by using at least one correct column alignment character in the tabular environment, for example by switching to \begin{tabular}{|c|}.

share|improve this answer

Your Answer


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