[Tex/LaTex] Section reference shows section then subsection number

cross-referencing

I am labeling a subsection with simply \label{labelname}, and referring to it later in my document with \ref{labelname}. However, at that point it doesn't print just the subsection number, e.g. 2.1, but it prints the section number followed by the subsection number, like 2 2.1. Can it be made to show the desired output?

Minimum example (using revtex4 class):

\documentclass[pre,12pt]{revtex4}
\renewcommand \thesection{\arabic{section}}
\renewcommand \thesubsection{\arabic{section}.\arabic{subsection}}
\renewcommand \thesubsubsection{\arabic{section}.\arabic{subsection}
\begin{document}
\section{Section 1}
\subsection{Subsection 1}
\label{subsection1}
Some text.

\section{Section 2}
Previously seen in \ref{subsection1}
\end{document}

Best Answer

The file revtex4.cls contains the lines

\def\thesubsection{\Alph{subsection}}
\def\p@subsection{\thesection\,}

so the representation for a cross-references to a subsection will be typeset as the upper-case alphabetic representation for the subsection counter prepended by the counter for sections and a thin space:

\documentclass[pre,12pt]{revtex4}

\begin{document}
\section{Section 1}
\subsection{Subsection 1}
\label{subsection1}
Some text.
\section{Section 2}
Previously seen in~\ref{subsection1}
\end{document}

enter image description here

Since you have redefined \thesubsection to explicitly include the section counter, you'll get this counter duplicated. To prevent this, you can redefine \p@subsection; for example to suppress the prefix and keep just the representation for the subsection counter you could say:

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

A complete example:

\documentclass[pre,12pt]{revtex4}
\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\arabic{section}.\arabic{subsection}}
\renewcommand\thesubsubsection{\arabic{section}.\arabic{subsection}}

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

\begin{document}
\section{Section 1}
\subsection{Subsection 1}
\label{subsection1}
Some text.

\section{Section 2}
Previously seen in \ref{subsection1}
\end{document}

enter image description here

A similar redefinition of \p@subsubsection will have to be done, since the class does

\def\p@subsubsection{\thesection\,\thesubsection\,}
Related Question