TransWikia.com

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

TeX - LaTeX Asked by aghsmith on June 11, 2021

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!

2 Answers

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}
usepackage{cleveref}% Load AFTER 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}

Correct answer by lockstep on June 11, 2021

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.

Answered by juliohm on June 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP