[Tex/LaTex] How to make \ref display only subsection

cross-referencingnumbering

I am using the revtex4 package and wanted to change the section numbers to arabic for all levels. Furthermore, I wanted the sections to be displayed as 1.2. (as opposed to 2. only).

I only use sections and subsections, so I did the following:

\def\thesection{\arabic{section}}
\def\thesubsection{\thesection.\arabic{subsection}}

Now the sections and subsections are displayed how I want them. However, referencing subsections is now broken. It displays like this (edited example):

\documentclass[twocolumn,pre,floats,aps,amsmath,amssymb,a4,floatfix]{revtex4}
\usepackage{acronym}
\usepackage[english]{babel}

\setcounter{secnumdepth}{3}
\pagenumbering{arabic}
\def\thesection     {\arabic{section}}
\def\thesubsection  {\thesection.\arabic{subsection}}

\begin{document}

\section{First Section}

\subsection{A Subsection}
\label{sub:example}
And then some text.

\section{Second Section}
Let's ref Section \ref{sub:example}.

\end{document}

what gets displayed

… instead of 1.1.

I see two resolutions, but don't know how to go about any of them:

  1. Change the display numbers of sections in a smarter way, OR

  2. Change what \ref displays (so that it displays only the subsection
    when subsections are referenced.

How can I achieve any of these, or is there another way?

Best Answer

A \label to some counter like subsection is normally constructed as \p@subsection\thesubsection . In most cases the "prefix" command \p@... doesn't typeset anything and thus the result is the same what is produced by \the.... Such "prefix" commands are only used by the standard classes to construct references like 1.a in enumerations when the items there are labeled 1 and the subitem a.

The revtex4.cls however is using the \p@...commands also for heading counters:

\def\thesection       {\Roman{section}}
\def\p@section        {}
\def\thesubsection    {\Alph{subsection}}
\def\p@subsection     {\thesection\,}
\def\thesubsubsection {\arabic{subsubsection}}
\def\p@subsubsection  {\thesection\,\thesubsection\,}

So if you change \thesubsection as you did you end up with the following:

\thesection\,\thesection.\arabic{subsection}

In other words you need to also change all the corresponding \p@...commands to expand to nothing. I the document preamble place:

\makeatletter
\def\p@subsection{}
\makeatother