0

When I type

$$ A_n\ =\ \left\{\begin{array}{ccc}
[\hskip.017in 0,1\hskip.017in] & {} & n\ {\rm is\ even} \\
[\hskip.017in -1,0\hskip.017in] & {} & n\ {\rm is\ odd} \\
\end{array}\right.\ , $$

I get an error message claiming "illegal unit of measure" and "missing number." I can't find anything wrong with the code. What am I missing?

David Carlisle
  • 757,742

2 Answers2

3

The problem is that the first [ follows \\ and is mistaken for introducing the optional argument. Use \relax or, better, use the proper tool.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$$ A_n\ =\ \left{\begin{array}{ccc} [\hskip.017in 0,1\hskip.017in] & {} & n\ {\rm is\ even} \ \relax [\hskip.017in -1,0\hskip.017in] & {} & n\ {\rm is\ odd} \ \end{array}\right.\ , $$

[ A_n=\begin{cases} [0,1] & \text{$n$ is even,} \ [-1,0] & \text{$n$ is odd,} \end{cases} ]

\end{document}

enter image description here

I have little doubts about which rendering is better both for input and output. If you want to align the two intervals to the right, add \hphantom{-}:

\[
A_n=\begin{cases}
\hphantom{-}[0,1]  & \text{$n$ is even,} \\
[-1,0] & \text{$n$ is odd,}
\end{cases}
\]

enter image description here

I'd avoid the comma hanging from nowhere.

Note that \rm has been deprecated for about 30 years and $$ since LaTeX version 1, about 40 years ago.

egreg
  • 1,121,712
2

the [is being seen as an optional argument, which takes a length, \\[5pt] so use

....\\ \relax
[....]

to hide the [ from \\

Note $$ and\hskip are TeX primitives that should not be used in LaTeX, use \[ and \hspace (but avoid \hspacein math) \rm has not been defined by default in latex since 1993, use \textrm{ is odd}

David Carlisle
  • 757,742