1

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} \subsectioncounter\label{somesubsection}\quad Some text \subsection{Later in the document} See \ref{somesubsection}. % I want this to print 1.1, not the section label. \end{document}

1 Answers1

2

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.

Willie Wong
  • 24,733
  • 8
  • 74
  • 106
  • +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 05:47
  • @Mico: I agree that is a better phrasing. – Willie Wong Nov 17 '20 at 13:58