I want to have sub-hypotheses so I use following code:
\newtheorem{hyp}{Hypothesis}
\makeatletter
\newcounter{subhyp}
\let\savedc@hyp\c@hyp
\newenvironment{subhyp}
{%
\setcounter{subhyp}{0}%
\stepcounter{hyp}%
\edef\saved@hyp{\thehyp}% Save the current value of hyp
\let\c@hyp\c@subhyp % Now hyp is subhyp
\renewcommand{\thehyp}{\saved@hyp\alph{hyp}}%
}
{}
\newcommand{\normhyp}{%
\let\c@hyp\savedc@hyp % revert to the old one
\renewcommand\thehyp{\arabic{hyp}}%
}
\makeatother
It works great, however there is no break in the hypothesis numbering across chapters. I want the counter on the hypotheses to restart at the beginning of each new chapter. Can anyone help me modify this to restart the counter?
Here is a MWE:
\documentclass{report}
\usepackage{ntheorem}}
\newtheorem{hyp}{Hypothesis}
\makeatletter
\newcounter{subhyp}
\let\savedc@hyp\c@hyp
\newenvironment{subhyp}
{%
\setcounter{subhyp}{0}%
\stepcounter{hyp}%
\edef\saved@hyp{\thehyp}% Save the current value of hyp
\let\c@hyp\c@subhyp % Now hyp is subhyp
\renewcommand{\thehyp}{\saved@hyp\alph{hyp}}%
}
{}
\newcommand{\normhyp}{%
\let\c@hyp\savedc@hyp % revert to the old one
\renewcommand\thehyp{\arabic{hyp}}%
}
\makeatother
\begin{document}
\chapter{This is Chapter 1}
\begin{subhyp}
\begin{hyp}
This is hypothesis 1A
\end{hyp}
\begin{hyp}
This is hypothesis 1B
\end{hyp}
\end{subhyp}
\chapter{This is Chapter 2}
\begin{subhyp}
\begin{hyp}
This should be hypothesis 1A
\end{hyp}
\begin{hyp}
This should be hypothesis 1B
\end{hyp}
\end{subhyp}
\end{document}
\usepackage{chngcntr}to your preamble, and add\counterwithin*{hyp}{chapter}after defining thehypenvironment. – Werner Jul 22 '15 at 06:22\newtheorem{hyp}{Hypothesis}[chapter]and\renewcommand{\thehyp}{\arabic{hyp}}– egreg Jul 22 '15 at 06:52