[Tex/LaTex] setcounter command doesn’t seem to work with question command in the exam class

exam

I read threw the manual for exam class at mit. I also did some searches, and found one that stated to use the \setcounter{question}{WANTED NUMBER}
I want to be able to change the number of the question ie {3,5,10,20343}

This is the error from texsudio

-> Something's wrong--perhaps a missing \item. \question $

Here is my code:

  \documentclass[10pt]{exam}
  \usepackage[a4paper]{geometry}
  \usepackage{graphicx}
  \usepackage{amssymb}
  \usepackage{epstopdf}
 \usepackage{amsmath}
 \usepackage{paralist}
 \usepackage{enumerate}
 \usepackage{wrapfig}
 \usepackage{xcolor}
 \usepackage{graphicx}
 \usepackage{tikz}



 \newcommand\dx[1]{\,\textrm{d}#1}
 \newcommand{\Lim}[1]{\raisebox{0.5ex}{\scalebox{0.8}{$\displaystyle \lim_{#1}\;$}}}
 \begin{document}

  \begin{questions}

In Exercises 1-6, find the equation of the tangent line $T$ to the graph of $f$ at the given point. Use this linear approximation to complete the table. 

\begin{tabular}{|c|c|c|c|c|c|}
\hline 
$x$ & 1.9 & 1.99 & 2 & 2.01 & 2.1 \\ 
\hline 
$f\left(x\right)$ &  &  &  &  &  \\ 
\hline 
$T\left(x\right)$ &  &  &  &  &  \\ 
\hline 
\end{tabular} 

\setcounter{question}{2}

\question $f\left(x\right) = x^5, \; \left(2,\sqrt{2}\right)$ <<<<Here it states and error with \item or \question>>>>>>

\begin{solution}

$f\left(x\right) = x^5$ 
$f^{\prime}\left(x\right) = 5x^4$
Tangent line at $\left(2,32\right)$
$\begin{array}{ccc}
y-f\left(2\right) & = & f^{\prime}\left(x-2\right) \\ 
               y-32& = & 80\left(x-2\right) \\ 
                 y & = & 80x-128
\end{array} $
\begin{tabular}{|c|c|c|c|c|c|}
\hline 
$x$ & 1.9 & 1.99 & 2 & 2.01 & 2.1 \\ 
\hline 
$f\left(x\right)= x^5 $ &24.761 & 31.208 & 32 & 32.808 & 40.841  \\ 
\hline 
$T\left(x\right)= 80x -128$ & 24 & 31.200 & 32 & 32.800 & 40.000 \\ 
\hline 
\end{tabular}

\end{solution}

\question $f\left(x\right)=\sqrt{x}, \; \left(2,\sqrt{2}\right)$
\begin{solution}
$f\left(x\right) = \sqrt{x}$ 
$f^{\prime}\left(x\right) = \frac{1}{2\sqrt{x}} = \frac{\sqrt{2}{4}$
Tangent line at $\left(2,\sqrt{2}\right)$
\begin{array}{ccc}
$y-f\left(2\right) & = & f^{\prime}\left(x-2\right) \\ 
               y-\sqrt{2}& = & \frac{\sqrt{2}{4}\left(x-2\right) \\ 
                 y & = & \frac{x\sqrt{2}}{4}+\frac{\sqrt{2}}{2}$
\end{array} 
\begin{tabular}{|c|c|c|c|c|c|}
\hline 
$x$ & 1.9 & 1.99 & 2 & 2.01 & 2.1 \\ 
\hline 
$f\left(x\right)= x^5 $ & 1.378 & 1.411 & 1.414 & 1.418 & 1.449  \\ 
\hline 
$T\left(x\right)= 80x -128$ & 1.379 & 1.411 & 1.414 & 1.418 & 1.450 \\ 
\hline 
\end{tabular}
\end{solution}
\end{questions}
\end{document} 

What am I doing incorrect?

Best Answer

There are currently three errors in your MWE that prevent it from compiling successfully.

  • You have material -- a sentence and an entire tabular environment -- that would be typeset by LaTeX between \begin{questions} and \setcounter{question}{2}. This is causing the error message about "perhaps a missing \item".

    To fix this error, move the \begin{questions} statement down to just before \setcounter{question}{2}.

  • In two instances, you have \frac{\sqrt{2}{4}, which is missing a right curly brace.

    Replace both of these instances with \frac{\sqrt{2}}{4}.

  • An array environment needs to be entirely in math mode. However, the one featured in the solution to the second question is not in math mode (though one of the cell entries is).

    To fix this, place the material from \begin{array}{ccc} to \end{array} in math mode, and remove the $ signs currently located inside the array environment:

    $\begin{array}{ccc}
    y-f\left(2\right) & = & f^{\prime}\left(x-2\right) \\
                   y-32& = & 80\left(x-2\right) \\
                     y & = & 80x-128
    \end{array} $
    

With these changes in place, your code should compile -- and the first question will be numbered 3. Separately, you're probably already aware of the fact that there are several errors in content (rather than syntax) in your MWE which need to be fixed.

Incidentally, I can't help but remark that you're overusing the \left( and \right) statements; none of the expressions currently encased by these constructs are actually "large" in the TeX sense. It's much better to use ordinary round parentheses, ( and ), in all of these cases. You'll find that the spacing around the parentheses is far more natural without these \left and \right qualifiers.

Related Question