3

Hey guys i'm getting this error in my tabular environment, is there something about the tabular environment that I'm missing, it's not a math mode, so I embbed it in an align*, or gather* but it doesn't compile well.

    \documentclass[12pt, letterpaper, oneside]{article}
    \usepackage{amsmath}
    \usepackage{amsthm}
    \usepackage{mathtools}
    \usepackage{tabularx}

    \begin{document}
        If not compiling, hit ctrl+z on the whole align* environment, leave this sentence, and compile the thing again, and then paste the code and compile it once more.
    \begin{align*}
        \begin{tabular}{c|cccccc}
            & -2 & -1 & 0 & 1 & 2 & 3\\ 
            \hline
            q_i & & & 1 & 1 & 3 & 5\\
            r_i & 703 & 399 & 304 & 95 & 19 & 0\\
            u_i & 1 & 0 & 1 & -1 & 4 & -21\\
            v_i & 0 & 1 & -1 & 2 & -7 & 37
        \end{tabular}
    \end{align*}
\end{document}

Any help will be appreciated :)

2
  • 2
    Welcome to tex.sx. I think you've identified the reason for the problem. tabular isn't math, and therefore isn't an appropriate candidate for including in any math environment. What is your actual goal? To center the result? If so, use \begin{center}...\end{center}. – barbara beeton Apr 13 at 0:11
  • Okay yeah that makes sense!! The goal was to simply make it compilable, which it wasn't with the tabular environment, thanks :> – Taken Spark Apr 13 at 11:16
8

You should make two separate changes.

  • The contents of the table -- not only the left-hand header column, but the 6 data columns as well -- need to be typeset in math mode rather than in text mode. I therefore suggest you switch from a tabular to an array environment.

  • You're abusing and misusing the align* environment. Please use \[ and \] instead of \begin{align*} and `\end{align*}.

Optionally, change the column type of the 6 data columns from c to r.

enter image description here

\documentclass[12pt, letterpaper]{article}
\usepackage{array}
\begin{document}
\[
\begin{array}{c|rrrrrr}
    &  -2 &  -1 &   0 &  1 &  2 &   3 \\ 
\hline
q_i &     &     &   1 &  1 &  3 &   5 \\
r_i & 703 & 399 & 304 & 95 & 19 &   0 \\
u_i &   1 &   0 &   1 & -1 &  4 & -21 \\
v_i &   0 &   1 &  -1 &  2 & -7 &  37
\end{array}
\]
\end{document}
1
  • I thought tabular behaved like the matrix environment, where you need to embed it in some sort of math-mode for it to work properly, my doubts are cleared and I will follow your suggestion of code, thank you!! – Taken Spark Apr 13 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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