1

I am using the cleveref package. My document looks something like this:

\documentclass{article}
\usepackage{cleveref}

\begin{document}
\tableofcontents

\section{Section A}
    Refer to \cref{append} for more details.

\appendix
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\Roman{subsubsection}}

\section{Appendix}
    \subsection{Appendix A}
        \subsubsection{Detailed Explanation} \label{append}
            blah
    \subsection{Appendix B}
\end{document}

I have to use subsections and subsubsections this way, because the appendix itself is required to have its own entry and section number in the ToC.

Now I want my output to be something along the lines of

Section A

Refer to Appendix A, Section I for more details.

I have already tried to use \crefname to customize the output:

\crefname{secapp}{Anhang \Alph{subsection}, Section}{Appendix \Alph{subsection}, Section}

%Stuff here
\subsubsection{Detailed Explanation} \label[secapp]{append}

but defining secapp like this causes cleveref to print the number of the subsection in which \cref was called.

Is there a way to format the output like described above using cleveref?

Thanks!

4
  • 1
    Please post a a compilable document, not just fragments.
    – user31729
    Jan 28, 2017 at 21:26
  • secapp is no counter which can be fed to \label[secapp]{append}
    – user31729
    Jan 28, 2017 at 21:45
  • Are you sticking to cleveref. I think this is something for zref rather!
    – user31729
    Jan 28, 2017 at 21:52
  • You're confusing \crefname with the formatting of the label. It can't work. Post a compilable minimal example.
    – Bernard
    Jan 29, 2017 at 0:14

1 Answer 1

1

The naming/numbering scheme is confusing, in my point of view, but using xassoccnt and its \RegisterPostLabelHook{\zlabel} macro automatically defines extra labels, storing the \thesubsection for the relevant appendix 'section', which is extracted with \parentCref later on.

\documentclass{article}
\usepackage{lipsum}
\usepackage{xassoccnt}
\usepackage{xpatch}
\usepackage{hyperref}
\usepackage[user,counter,hyperref]{zref}
\usepackage{cleveref}

\makeatletter
\AtEndPreamble{
  \newif\if@hyperrefloaded
  \@ifpackageloaded{hyperref}{
    \@hyperrefloadedtrue
  }{
    \@hyperrefloadedfalse
  }
}
\makeatother


\usepackage{xparse}

% Define a new property named 'appendix'

\makeatletter
\zref@newprop{appendix}{\thesubsection}

% Add the new property to the main property list stored with \zlabel, but for \appendix only
\g@addto@macro{\appendix}{%
  \zref@addprops{main}{appendix}%
}

% Command for uppercase output
\NewDocumentCommand{\parentCref}{m}{%
  \zref@ifrefundefined{#1}{%
    \Cref{#1}%
  }{%
    \if@hyperrefloaded
    \hyperlink{\zref@extract{#1}{anchor}}{\appendixname\ \zref@extract{#1}{appendix}, Section \zref@extract{#1}{default}}%
    \else
    \appendixname\ \zref@extract{#1}{appendix}, Section \zref@extract{#1}{default}%
    \fi
  }%
}
\makeatother


\AtBeginDocument{%
 \RegisterPostLabelHook{\zlabel}
}

\begin{document}


\section{Normal section} \label{firstsection}
Refer to \parentCref{append} for more details, but don't forget \parentCref{append:b}.

\appendix
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\Roman{subsubsection}}


\clearpage

\section{Appendix}
\subsection{Appendix A}
\subsubsection{Detailed Explanation} \label{append}
blah
\subsection{Appendix B} \label{appendix:B}
\subsubsection{Even more detailed explanations} \label{append:b}


\end{document}




%\crefname{subsubappendix}{\appendixname \Alph{subsection}, Section}{\appendixname \Alph{subsection}, Section}

\crefformat{subsubappendix}{#2\appendixname\ thesubappendix, Section  #1#3}
\Crefformat{subsubappendix}{#2\appendixname\ thesubappendix, Section  #1#3}

\begin{document}
\tableofcontents

\section{Section A} \label{firstsection}
Refer to \cref{append} for more details, but don't forget \Cref{append:b}.

\appendix
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\Roman{subsubsection}}



\section{Appendix}
\subsection{Appendix A}
\subsubsection{Detailed Explanation} \label{append}
blah
\subsection{Appendix B} \label{appendix:B}
\subsubsection{Even more detailed explanations} \label{append:b}

\end{document}

enter image description here

You must log in to answer this question.

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