# \autoref should call sections within the appendix "appendix" not "section"

I make use of autoref thoughout my now rather long document. I have an appendix with sections, though currently a small number, so changes could be made here.

I want references in my document to sections within the appendix to say something like appendix A.1 instead of section A.1 but still refer to sections not in the appendix by section. I had an idea along the lines of creating some alias to section which had their own autorefname and using these instead of section. I tried and failed to use aliascnt for this. I don't know if it was because I was doing it wrongly or because it can't do what I wanted.

Any help would be appreciated!

I assume you're using a class that includes the \chapter command (e.g. book or report). In that case, within the appendix \autoref will refer to chapters as "Appendix", but to sections still as "section" (contrary to the article class, where sections would constitute an "Appendix"). Solution: (EDIT: My first "solution" was very ill-advised) Load cleveref after hyperref and use \cref instead of \autoref. (Yes, the links won't be as pretty as before.)

\documentclass{report}

\usepackage{hyperref}

% \crefname{subappendix}{fairy tale}{fairy tales}

\begin{document}

\chapter{bla}\label{bla}

\section{blubb}\label{blubb}

As shown in \cref{foo} and especially in \cref{bar} \dots

\appendix

\chapter{foo}\label{foo}

\section{bar}\label{bar}

As shown in \cref{bla} and especially in \cref{blubb} \dots

\end{document}

• Dear lockstep, thanks very much for this. In fact I had tried this solution with no success. There is possibly a misunderstanding about what I want it to do... I would like a reference to the appendix, written before the start of the appendix to refer to it as "appendix A.1" not just references (autorefs) written after the start of the appendix. Nov 22, 2010 at 19:00
• ok, i'm excited by the new solution, just investigating it now Nov 22, 2010 at 20:07
• Ok. I can see that cref is going to take a while to master. but in the mean time it has sorted out the underlying problem. I'm a bit worried that my labels might not all be 100% propper but... we will see. Cheers Nov 22, 2010 at 20:28
• You can get nicer looking links with something along the lines of \crefformat{chapter}{#2chapter~#1#3} and \Crefformat{chapter}{#2Chapter~#1#3}.
– mpr
Oct 29, 2011 at 4:33
• @lockstep: Is there really no way to do this without cleveref? Jan 26, 2012 at 19:39

The simplest workaround is to define a new command:

\newcommand{\aref}[1]{\hyperref[#1]{Appendix~\ref*{#1}}}


and use it for appendix sections:

\aref{sec:appendix_section}


The star in \ref* means not to make this reference number into a link since \hyperref[#1]{...} already does so.

• Tried this - doesn't work. Aug 20, 2021 at 18:35