9

I would like to reset the counter that appears next to equations in \begin{equation} and \begin{align} so that my last homework problem doesn't refer to an equation several lines up as equation 42. Is there a way to do that?

EDIT:

Due to the need to adhere to a template, I can't use sections and therefore \numberwithincannot be used

EDIT #2:

The template is

\documentclass[letterpaper,12pt,twoside]{article}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[letterpaper, top = 1.5in, left = 1in, right = 1in, bottom = 1.5in]  
\usepackage{fancyhdr}       
\usepackage{amsfonts,amsmath,amsthm,amssymb}    

\title{}
\author{Author}     
\date{\today}               

\makeatletter               
\let\Author\@author         
\let\Date\@date             
\makeatother

\newcommand{\Problem}{\relax}
\newcounter{problemcount}
\newcommand{\nextproblem}[1]{\renewcommand{\Problem}{#1}\setcounter{equation {0}\setcounter{page}{0}}

\pagestyle{fancy}
\lhead{\Problem}
\chead{}
\rhead{
\Author
\\
Class
\\
Section
\\
\Date
}

\renewcommand{\headrulewidth}{0.4pt}
\setlength{\headheight}{56.2pt}
\setlength{\parindent}{0pt}

\makeatother

\begin{document}
\nextproblem{Problem 1}
\begin{proof}\begin{align*}1+1&=2\\2&=2\end{align*}\end{proof}
\newpage

\nextproblem{Problem 2}\begin{proof}\begin{align*}1+1&=2\\2&=2\end{align*}\end{proof}

\end{document}
8
  • 5
    You can always use \setcounter{thecounter}{0} Commented Sep 21, 2014 at 15:45
  • 6
    \setcounter{equation}{0} as Sean Allred wrote
    – user31729
    Commented Sep 21, 2014 at 15:50
  • 1
    Alternatively,there is a \@addtoreset, for example in a subsection possible, but this depends on the structures of the home work document
    – user31729
    Commented Sep 21, 2014 at 15:56
  • 4
    It's called an XY problem. You ask for X but in fact you need to solve Y. Better post your Y instead.
    – percusse
    Commented Sep 21, 2014 at 16:21
  • 1
    You've posted a template, but it's not clear which counter is giving you problems. Is it the counter for equations? If so, what exactly is the current problem, and how would you like to see it fixed?
    – Mico
    Commented Sep 21, 2014 at 17:21

2 Answers 2

11

If you describe each problem in a different section, you may have a look at the numberwithin command provided in the amsmath package. For example: \numberwithin{equation}{section}. It just does \setcounter{equation}{0} automatically.

5
  • Not what I was looking for. Due to the need to adhere to a template, I can't use vanilla sections.
    – 0az
    Commented Sep 21, 2014 at 16:05
  • @alphadelta: You should rather provide this 'template' instead of letting users making educated guesses. In principle, the solution by U.Martinez-Corral should work in any well - behaving template or .cls file ;-)
    – user31729
    Commented Sep 21, 2014 at 16:10
  • @ChristianHupfer Yeah. +1 upvote for good answer that fits most cases.
    – 0az
    Commented Sep 21, 2014 at 16:16
  • @alphadelta +1ing is fine but either mark this as not-accepted or ask a new question. Your question will get much less attention if you have accepted an answer since people will assume that you already have a suitable solution and there is no puzzle left to solve.
    – cfr
    Commented Sep 21, 2014 at 17:55
  • @alphadelta Of course, that's assuming that your edits to the question are accurate. Judging from the comments, I'm not clear whether this solution worked for you in the end or not.
    – cfr
    Commented Sep 21, 2014 at 17:58
2

Your code did not compile as is. I made some corrections, and added the necessary lines in order to get what you want. If I understand well, page numbers are reset at every problem, as are the equation numbers.

The latter problem is addressed by loading the chngcntr package, which allows to reset a counter whenever any chosen counter changes. However, this doesn't work with the page counter, but simply adding the \page numbering{arabic} in the code that defines the \nextproblem command does the job.

\documentclass[letterpaper,12pt,twoside]{article}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[letterpaper, top = 1.5in, left = 1in, right = 1in, bottom = 1.5in]{geometry}
\usepackage{fancyhdr}
\usepackage{amsfonts,amsmath,amsthm,amssymb}
\usepackage{chngcntr}
\title{}
\author{Author}
\date{\today}

\makeatletter
\let\Author\@author
\let\Date\@date
\makeatother

\newcommand{\Problem}{\relax}
\newcounter{problemcount}
\setcounter{problemcount}{0}

\newcommand{\nextproblem}[1]{\clearpage\stepcounter{problemcount}\pagenumbering{arabic}\renewcommand{\Problem}{#1}}
\counterwithin*{equation}{problemcount}

\pagestyle{fancy}
\lhead{\Problem}
\chead{}
\rhead{
\Author
\\
Class
\\
Section
\\
\Date
}

\renewcommand{\headrulewidth}{0.4pt}
\setlength{\headheight}{56.2pt}
\setlength{\parindent}{0pt}

\makeatother

\begin{document}
\nextproblem{Problem 1}
\begin{proof}\begin{align}1+1&=2\\2&=2\end{align}\end{proof}
\newpage

\nextproblem{Problem 2}
\begin{proof}\begin{align}1+1&=2\\2&=2\end{align}\end{proof}

\end{document} 

enter image description here

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .