3

I have the following code:

\begin{array}{cc|c|c|}
     & & \multicolumn{2}{c}{odd} \\
     &  & 0 & 1 \\
    \cline{3-4}
    \multirow{2}{*}{even} & 0 & $(+1,-1)$ & $(-1,+1)$ \\
    \cline{3-4}
     & 1 & $(-1,+1)$ & $(+1,-1)$ \\
    \cline{3-4}
\end{array}

It gives me a "missing $ inserted" error, and produces the following table: enter image description here

As you might see, there are two issues:

  1. Some of the cells are in math environment and some aren't, and it's almost the opposite of my intentions. I get that it has something to do with the error, but I can't see what's the problem or how to fix it - I simply put $...$ inside a cell that should be in math mode! Just to make it clear, I want the titles "odd", "even", "0", "1" to be regular text, and the vectors to be in math mode.
  2. I don't know how to get rid of the upper parts of the three vertical lines. I want them to only strech across the two bottom cells, symmetrically to the horizontal lines.

I'd appriciate to hear your suggestions.

  • The array environment must occur in math mode. In your example, LaTeX encounters the instruction \begin{array}{cc|c|c|} in text mode and hence issues a complaint. – Mico May 6 at 17:17
4

Here are two different versions using either an array or a tabular environment:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow}
\begin{document}
\[
\begin{array}{cc|c|c|}
    \multicolumn{2}{c}{} & \multicolumn{2}{c}{\text{odd}} \\
    \multicolumn{2}{c}{} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{1} \\
    \cline{3-4}
    \multirow{2}{*}{\text{even}} & 0 & (+1,-1) & (-1,+1) \\
    \cline{3-4}
     & 1 & (-1,+1) & (+1,-1) \\
    \cline{3-4}
\end{array}
\]



\begin{tabular}{cccc}
     &  & \multicolumn{2}{c}{odd} \\
     & & 0 & 1 \\
    \cline{3-4}
    \multirow{2}{*}{even} & 0 &  \multicolumn{1}{|c|}{\((+1,-1)\)} & \multicolumn{1}{c|}{\((-1,+1)\)} \\
    \cline{3-4}
     & 1 & \multicolumn{1}{|c|}{\((-1,+1)\)} & \multicolumn{1}{c|}{ \((+1,-1)\)} \\
    \cline{3-4}
\end{tabular}

\end{document}
  • array based approach: Place the whole array in math mode (via \[ and \]) and use \text from amsmath for the texts.

  • tabular based appoach: Just place the contents of each cell into math mode (via \( and \)).

  • globally defined vertical lines: Use \multicolumn{1}{c}{} to remove the vertical lines where you don't want them

  • locally added verticcal lines: Define your table without vertical lines and use \multicolumn{1}{|c|}{...} or \multicolumn{1}{c|}{...} to add them whenever needed.

| improve this answer | |
  • 1
    +1. You might want to replace \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & with \multicolumn{2}{c}{} &, though. – Mico May 6 at 17:24

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.