2

In the following MWE, how to get the desired format of the cross-references of the questions, parts, subparts, and subsubparts of the exam class with/without cleveref package?

\documentclass[12pt]{exam}
\usepackage{greekctr,hyperref,cleveref}

\renewcommand\partlabel{(\alph{partno})}
\renewcommand\subpartlabel{(\roman{subpart})}
\renewcommand\subsubpartlabel{(\greek{subsubpart})}

\begin{document}

    \begin{questions}
        \question The main question. \label{myquestion}
        \begin{parts}
            \part text \label{mypart}
                \begin{subparts}
                \subpart text \label{mysubpart}
                \begin{subsubparts}
                    \subsubpart text \label{mysubsubpart}
                \end{subsubparts}
            \end{subparts}
        \end{parts}
    \end{questions}



I need to respectively print the cross-references of the\\

 question (\verb|\cref{myquestion}|) \cref{myquestion},\\
 part (\verb|\cref{mypart}|) \cref{mypart},\\
 subpart (\verb|\cref{mysubpart}|) \cref{mysubpart} ,\\
 and subsubpart (\verb|\cref{mysubsubpart}|) \cref{mysubsubpart} as\\

 ``question (1)'', ``part (a)'', ``subpart (i)'', and ``subsubpart ($\alpha$)''.

\end{document}

1 Answer 1

2

cleveref needs the coupling of the counter name (partno, subpart, subsubpart) with their textual version, i.e. partnoPart number etc.

This coupling is done with

\crefname{partno}{part number}{part numbers}

where part number is used for a single reference and part numbers is the plural form.

For upper case use \Crefname{partno}{Part number}{Part numbers}, \Cref can applied then as well.

Please choose the names of their appearence in text as you like.

\documentclass[12pt]{exam}
\usepackage{greekctr,hyperref,cleveref}

\renewcommand\partlabel{(\alph{partno})}
\renewcommand\subpartlabel{(\roman{subpart})}
\renewcommand\subsubpartlabel{(\greek{subsubpart})}

\crefname{subpart}{sub part}{sub parts}
\crefname{subsubpart}{subsub part}{sub sub parts}
\crefname{partno}{part number}{part numbers}
\crefname{question}{question}{questions}


\creflabelformat{question}{(#2#1#3)}
\begin{document}

    \begin{questions}
        \question The main question. \label{myquestion}
        \begin{parts}
            \part text \label{mypart}
                \begin{subparts}
                \subpart text \label{mysubpart}
                \begin{subsubparts}
                    \subsubpart text \label{mysubsubpart}
                \end{subsubparts}
            \end{subparts}
        \end{parts}
    \end{questions}



I need to respectively print the cross-references of the\\

 question (\verb|\cref{myquestion}|) \cref{myquestion},\\
 part (\verb|\cref{mypart}|) \cref{mypart},\\
 subpart (\verb|\cref{mysubpart}|) \cref{mysubpart} ,\\
 and subsubpart (\verb|\cref{mysubsubpart}|) \cref{mysubsubpart} as\\

 ``question (1)'', ``part (a)'', ``subpart (i)'', and ``subsubpart ($\alpha$)''.

\end{document}

enter image description here

2
  • 1
    Sorry for the late reply. First, thanks for your answer. Second, How can I make the output, for example, question (1) instead of question 1?
    – Diaa
    Jan 14, 2019 at 5:50
  • 2
    @Diaa: \creflabelformat{question}{(#2#1#3)}, see the update of the code, the image is not updated yet. #2 and #3 are needed for hyperlinks, so do not remove them.
    – user31729
    Jan 14, 2019 at 18:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .