# Changing numbers in theorems

I want the number in the first theorem to be 1.1 and not 1.0.1. The number 1.1.1 of the second theorem is right. What can I do?

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsthm}
\usepackage{empheq}
\theoremstyle{plain}
\newtheorem{thm}{theorem}[subsection]

\begin{document}
\section{1st section}
\begin{thm}
Some theorem.
\end{thm}
\subsection{1st subsection}
\begin{thm}
Some theorem.
\end{thm}
\end{document}


Thanks!

• Well, you didn't use a subsection before the first theorem, that's why the numbering is wrong, but you can try \counterwithin{thm}{section} \begin{thm} Some theorem. \end{thm} \counterwithin{thm}{subsection}, after \section{1st section} -- this requires \usepackage{chngcntr} – user31729 Aug 30 '16 at 10:13

Check whether the subsection number is 0 and, in this case, issue \thesection, otherwise issue \thesubsection.

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsthm}
\usepackage{empheq}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[subsection]

\renewcommand{\thethm}{%
\ifnum\value{subsection}>0
\thesubsection
\else
\thesection
\fi
.\arabic{thm}%
}

\begin{document}
\section{1st section}
\begin{thm}
Some theorem.
\end{thm}
\subsection{1st subsection}
\begin{thm}
Some theorem.
\end{thm}
\end{document}