# Label section from \thesection

How can I put a label on \thesubsection without using \subsection?

MWE:

\documentclass{article}
\usepackage[english]{babel}

\newcommand*{\subsectioncounter}{\stepcounter{subsection}\thesubsection}

\begin{document}
\section{A section}
\subsection*{An un-numbered subsection}
\subsection*{Later in the document}
See \ref{somesubsection}. % I want this to print 1.1, not the section label.
\end{document}

• use \refstepcounter instead of \stepcounter – Willie Wong Nov 17 '20 at 5:02
• @WillieWong wow, thanks, I've been searching for a solution for this for quite a while! If you make this an answer I can make it the accepted answer :-) – Jake Ireland Nov 17 '20 at 5:06
• Done; incidentally, many moons ago that ended up as an answer to one of my questions. However, since I didn't realize that was what I should have asked about, I doubt you would've been able to find it in the site search. – Willie Wong Nov 17 '20 at 5:13
• For an in-depth discussion, see Understanding how references and labels work – Mico Nov 17 '20 at 5:51

You should use \refstepcounter instead of \stepcounter for this.
The former does the same as the latter, except it also associate subsequent \label statements with the value of the counter being incremented.
• +1. However, I would replace "sets the current \ref value to be the counter being incremented" with "associates the next \label statement with the value of the counter being incremented". – Mico Nov 17 '20 at 5:47