0

I have a book documentclass for which I would like to include subappendices after each chapter. Something seems to go wrong with the autoref names after including a subappendix.

Here's an example:

\documentclass{book}
\usepackage{appendix}
\usepackage{hyperref}

\begin{document}

\chapter{One}
Reference to \autoref{chapter_2}. Reference to \autoref{appendix_1}. Reference to \autoref{chapter_3}.

\chapter{Two}
\label{chapter_2}

\begin{subappendices}
\section{hello}
\label{appendix_1}
\end{subappendices}

\chapter{Three}
\label{chapter_3}

\end{document}

Of which the output for chapter One is:

enter image description here

The reference to chapter_2 is as expected. Two problems with the output:

  1. I would like

Reference to section 2.A.

to be:

Reference to Appendix 2.A.

(or similar; but an "appendix" somewhere in the autoref). How can I achieve that?

  1. The reference to chapter_3 is

Appendix 3

even though I would expect/want this to be:

chapter 3

Why is that chapter referenced as an appendix?

Any help much appreciated.

4
  • 1
    well regarding chapter 3 I would say the appendix package is doing nonsense here. And regarding the section, that autoref is not powerful enough for this (it tries to guess the name from the counter and this doesn't change here. Commented Jul 14, 2021 at 15:12
  • I changed your section 3 to chapter 3.
    – citsahcots
    Commented Jul 14, 2021 at 15:37
  • @UlrikeFischer is right that the appendix package “is doing nonsense” here: hyperref.sty defines \def\Hy@chapapp{\Hy@chapterstring}. This is overwritten by \xdef\Hy@chapapp{\Hy@appendixstring} in appendix.sty. Hence, adding \makeatletter \renewcommand{\Hy@chapapp}{\Hy@chapterstring} \makeatother after \end{subappendices} to restore the original meaning of \Hy@chapapp solves the second issue. Commented Feb 16, 2023 at 15:24
  • Alternatively, use \usepackage{etoolbox} \makeatletter \patchcmd\@resets@pp{\xdef}{\def}{}{\fail} \patchcmd\@resets@ppsub{\xdef}{\def}{}{\fail} \makeatother after loading the appendix package, as Ulrike Fischer suggested on GitHub: github.com/wspr/herries-press/issues/34#issuecomment-935770824. Commented Feb 16, 2023 at 15:56

1 Answer 1

3

Using \cref from cleveref immediately fixed the second problem. Using \label[appendix]{appendix_1} fixed the first problem.

\documentclass{book}
\usepackage{appendix}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{parskip}

\begin{document}

\chapter{One}
Reference to \autoref{chapter_2}. Reference to \autoref{appendix_1}. Reference to \autoref{chapter_3}.

Reference to \cref{chapter_2}. Reference to \Cref{appendix_1}. Reference to \cref{chapter_3}.


\chapter{Two}
\label{chapter_2}

\begin{subappendices}
\section{hello}
\label[appendix]{appendix_1}
\end{subappendices}

\chapter{Three}
\label{chapter_3}

\end{document}

enter image description here

3
  • 1
    I'll accept this answer because using cleveref solved both problems for me. The second as you indicated and the first by overriding the cross-reference type of the label in the appendix by \label[appendix]{appendix_1}.
    – MMM
    Commented Jul 15, 2021 at 13:26
  • @MMM, Good to know that both problems are solved!!
    – citsahcots
    Commented Jul 15, 2021 at 13:30
  • I just updated my answer to include your solution for the first problem.
    – citsahcots
    Commented Jul 15, 2021 at 13:38

You must log in to answer this question.

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