# Cross-reference format in exam class

I need to reference a part in a question, but I have the part redefined to include the number of the question as well. How can I make the reference format to show this as well?

\documentclass[12pt]{exam}
\renewcommand{\thepartno}{\arabic{partno}}
\renewcommand{\partlabel}{\bfseries\thequestion.\thepartno.}
\begin{document}
\qformat{\textbf{\large{Problem \thequestion}} \hfill \vrule depth 1em width 0pt}
\begin{questions}
\question
The main question.
\begin{parts}
\part
This is part 1.1. \label{mylabel}
\part
This is part 1.1 but it is related to part \ref{mylabel} somehow.
\end{parts}
\end{questions}
\end{document}


This shows "This is part 1 but it is related to part 1 somehow.", instead of "This is part 1 but it is related to part 1.1 somehow."

The LaTeX referencing system uses \thepartno, so you have to add the question in \thepartno instead of only adding it in \partlabel.

\documentclass[12pt]{exam}
\renewcommand{\thepartno}{\thequestion.\arabic{partno}}
\renewcommand{\partlabel}{\bfseries\thepartno.}
\begin{document}
\qformat{\textbf{\large{Problem \thequestion}} \hfill \vrule depth 1em width 0pt}
\begin{questions}
\question
The main question.
\begin{parts}
\part
This is part 1.1. \label{mylabel}
\part
This is part 1.1 but it is related to part \ref{mylabel} somehow.
\end{parts}
\end{questions}
\end{document}

• Duh, why didn't I think of this. Thanks! – ralk912 Mar 18 '18 at 19:52
• I would be grateful if you could edit your answer to include how it is done using cleveref. Thanks – Diaa Nov 10 '18 at 8:31