\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep


\author{Nguyen Van Manh \\ HE170552}


The augmented matrix of the system:

I get error: Package amsmath: Erroneous nesting of equation structures;\n(amsmath) trying to recover with `aligned'.

What is cause of it? How to fix it?

I was tried:


I don't get the above error at the moment but it looks like it didn't align

  • 1
    It isn't that obvious to me how it's supposed to look, but maybe use the aligned environment rather than alignat*?
    – frabjous
    Commented Oct 14, 2022 at 3:02

1 Answer 1


In the line


both \[ and \begin{alignat*} initiate standalone display-math mode. That can't go well; hence the error message.

I think what you need to do is replace \begin{alignat*} with \begin{array}{rrrr} and, a few lines down, replace \end{alignat*} with \end{array}.

In view of the fact that you've redefined the low-level \env@matrix macro, you could also replace \left[\begin{alignat*} and \end{alignat*}\right] with \begin{bmatrix}[rrrr] and \end{bmatrix}, respectively.

Addendum to address the OP's claim that


should "work". It doesn't -- the alignment of the columns is poor. What would work is


However, I don't think that anyone should prefer this to


i.e., the solution I have earlier.

  • Thank sir, it's work. But when also tried with \begin{alignedat}{4} and it also work, however it doesn't seem align. can you explain why? I will add it to the question section.
    – manh3
    Commented Oct 14, 2022 at 3:13
  • @manh3 - I've edited my answer to answer your claim that \begin{alignedat}{4} "also works". In my view, it does not.
    – Mico
    Commented Oct 14, 2022 at 3:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .