2

I am doing my homework, and each of the problems is an "item", part of an itemized list. Each problem has some equations which I am numbering. I want the numbers to look like [item].[equation-number]. I am aware of the command numberwithin, but it doesn't work for items, throwing compiling errors. Code provided below:

\documentclass[11pt]{article}
\usepackage{amssymb,amsmath,amsthm}
\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}

%\numberwithin{equation}{item}

\pagestyle{empty}

\begin{document}

\begin{enumerate}

   \item 
    \setcounter{equation}{0}
    We have the following amazing equation: \[ a = 6. \numberthis\label{p1}\]
    We also have this beautiful equation: \[a1 = 17. \numberthis\label{p1-2}\]


   \item 
   \setcounter{equation}{0}
   More amazingness here: \[ b = 7.\numberthis\label{p2}\]


\end{enumerate}

\end{document}

(Uncomment the line numberwithin... and compile to see the error). I am using numberthis as a new command that I found the code for somewhere on tex stackexchange, and I'd prefer to not remove it, since it works very well for me across various math environments.

What I want to see is (1.1), (1.2) ... for Problem 1, (2.1), (2.2)... for Problem 2, etc.

Thank you!

4

You need to know the correct counter name, wich is enumi for the first level of enumerate. And if you use an environment like equation, wich automatically numbers the equation, you don't need additional macros.

\documentclass[11pt]{article}
\usepackage{amssymb,amsmath,amsthm}

\numberwithin{equation}{enumi}

\pagestyle{empty}

\begin{document}

\begin{enumerate}
\item 
    We have the following amazing equation:
    \begin{equation}
        a = 6.         \label{p1}
    \end{equation}
    We also have this beautiful equation:
    \begin{equation}
        a1 = 17.       \label{p1-2}
    \end{equation}

\item 
    More amazingness here:
    \begin{equation}
        b = 7.        \label{p2}
    \end{equation}


\end{enumerate}

\end{document}
  • This is beautiful, works exactly as I want! Thanks! :) – lazulikid Sep 29 '17 at 3:59

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.