# How to change the number of a subsection used in a cross-reference? [duplicate]

I was wondering if I could change the number that appears in my "\labelcref"? (I use hyperref, cleveref and nameref packages) More precisely, I'm writing a document where there are several sections which are composed by a few subsections. I wrote the code:

\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}


So that my sections go by I,II,III,... and every subsection by 1,2,3,..(and not I.1,I.2,..).

But I'd like to have "see I.1" and not "see 1" (which could confuse the reader because it doesn't state in which section it is). My code looks like that:

\documentclass[10pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm, thmtools}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{lmodern}
\usepackage{soul}
\usepackage{mathrsfs}
\usepackage{enumitem}
\usepackage{xcolor}
\usepackage{hyperref, nameref, cleveref}

\begin{document}

\section {First}
\subsection {one} \label{I.1}
blablabla
\subsection {two}
blablabla
\section {Second}
\subsection {one}
blablabla and see \labelcref{I.1}
\end{document}


## marked as duplicate by Mico, Svend Tveskæg, ChrisS, Jesse, Reinstate Monica - M. SchröderMar 21 '14 at 23:59

• Welcome to TeX.SX! Could you please edit and improve your post and include a (minimal) working example starting with \documentclass... and ending with \end{document}? It is almost impossible for us to help you if we don't know crucial details (structure of the document, loaded packages and loading order, used commands etc). – Malipivo Mar 21 '14 at 22:17

The LaTeX kernel already provides a mechanism for what you want: whenever \label is called, the current reference is made by expanding

\p@foo\thefoo


where foo is the most recently “refstepped” counter. Usually \p@foo (in your case \p@subsection) is defined to expand to nothing. So here's a minimal example for what you should do (I removed all the inessential packages, to better show the main part of the code).

\documentclass[10pt,a4paper]{article}
\usepackage{hyperref, nameref, cleveref}

\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\arabic{subsection}}

\makeatletter
\renewcommand{\p@subsection}{\thesection.}
\makeatother

\begin{document}
\section {First}
\subsection {one} \label{I.1}
blablabla
\subsection {two}
blablabla
\section {Second}
\subsection {one}
blablabla and see \labelcref{I.1} (also known as \cref{I.1})
\end{document}


• First of all it does work so thank you very much! But I'm not sure I understood all about the way "\p@foo" works... If I got I wright it's just the name of the counter foo? But why renaming it for section counter change the way it appears in the cross-references? – WrabbitW Mar 21 '14 at 23:53
• @WrabbitW It is a "prefix” to the representation of the counter, used only in the context of \ref and not when printing the counter's value, where only \thefoo would be used. – egreg Mar 21 '14 at 23:57