2

I'm trying to create a matrix using the below commands:

\begin{equation}
  \psi =
  \begin{pmatrix}
    [{\overrightarrow{\sigma} \cdot (\overrightarrow{P} -
      e\overrightarrow{A}) + (p_{0} - eA_{0}) + m}]\phi \\
    [{\overrightarrow{\sigma} \cdot (\overrightarrow{P} -
      e\overrightarrow{A}) + (p_{0} - eA_{0}) - m}]\phi \\
  \end{pmatrix}
\end{equation}

I'm getting the message in the title. Could you please help me?

4
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – Frenzy Li
    Jul 6, 2016 at 5:57
  • What you've provided works for me, I think your problem may perhaps be elsewhere?
    – Au101
    Jul 6, 2016 at 6:00
  • 5
    A complete MWE that replicates the problem would be necessary here. I tried running your code in a black document, with only \usepackage{amsmath} loaded, and it seems to work. You could try loading that package, and see if helps, might be as simple as that. Otherwise, an MWE is a must here.
    – Runar
    Jul 6, 2016 at 6:00
  • 2
    pro-tip, you might consider using \vec{foo} instead of \overrightarrow{foo}. Also I've added a little bit of whitespace to your code. This was mostly so that it could be hard wrapped and therefore it wouldn't be necessary to scroll to read the code on the site, but you might find it helpful generally for code reability
    – Au101
    Jul 6, 2016 at 6:04

1 Answer 1

5

As @RunarTrollet has pointed out, you need to load the correct packages. My comment had been made upon the following addition to your example code.

\documentclass{article}
\begin{document}
\begin{equation}
\psi= \begin{pmatrix}
          [{\overrightarrow{\sigma}\cdot(\overrightarrow{P}-e\overrightarrow{A})+(p_{0}-eA_{0})+m}]\phi  \\
          [{\overrightarrow{\sigma}\cdot(\overrightarrow{P}-e\overrightarrow{A})+(p_{0}-eA_{0})-m}]\phi  \\
            \end{pmatrix}
\end{equation}
\end{document}

(Notice that I have added \documentclass{article}, \begin{document} environments, in order to construct a Minimum Working Example.)

Now that I can reproduce your error, I went on to provide this link whose first answer explains the syntax error: \\ followed by [ on the next line will not be interpreted in the way you thought it will do.

However, inserting

\usepackage{amsmath}

before the beginning of the document (before \begin{document}) will change the behavior of \\ to produce your intended matrix notation. For more information on \\, consult here and here.

1
  • This is a super answer. I completely forgot about the problem with the [ after \\ because I have always used amsmath and so it's never been a problem within a matrix environment (out in the main document of course is another matter). Good deduction
    – Au101
    Jul 6, 2016 at 6:31

You must log in to answer this question.

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