34

Using this example:

\documentclass{scrartcl}
\usepackage{lipsum}
\usepackage{appendix}
\usepackage{cleveref}

\begin{document}
\section{The first section}\label{sec:1}
\lipsum[2]

\section{The second section}
\cref{sec:1} tells us something, while \cref{app:1} tells us something else!

\begin{appendices}
  \section{The first appendix}\label{app:1}
  \lipsum[2]
\end{appendices}

\end{document}

The reference \cref to the appendix section unfortunately references it as “section A”, rather than “appendix A”.

Is there any way to fix that?

section 1 tells us something, while section A tells us something else!

One solution I found is this: Create an additional \crefname and use it as an optional argument to \label.

36

New answer

The package cleveref allows one to alias different counters to other ones, and this works locally in groups. So one solution is to add

\crefalias{section}{appendix}

just after \begin{appendices}. You can do this globally using \AtBeginEnvironment from etoolbox.

Sample output

\documentclass{scrartcl}

\usepackage{lipsum} % for dummy text

\usepackage{etoolbox}
\usepackage{appendix}
\usepackage[capitalize]{cleveref}

\AtBeginEnvironment{appendices}{\crefalias{section}{appendix}}

\begin{document}

\section{The first section}
\label{sec:1}

\lipsum[2]

\section{The second section}

\Cref{sec:1} tells us something, while \cref{app:1} tells us something
else!  In \cref{app:2}, we see that this is self-contradictory.  All
is fine again in \cref{sec:3}.

\begin{appendices}
  \section{The first appendix}
  \label{app:1}
  \lipsum[2]
  \subsection{An appendix subsection}
  \label{app:2}
  \lipsum[3]
\end{appendices}

\section{The third section}
\label{sec:third-section}
\label{sec:3}

\lipsum[4]

\end{document}

Old answer

The package cleveref provides a mechanism for this. Introduce a new type appsec and set up the label name via \crefname; then in the appendices part use \crefalias to get the section type to point to the type appsec:

Sample output

\documentclass{scrartcl}
\usepackage{lipsum}
\usepackage{appendix}
\usepackage[capitalize]{cleveref}

\Crefname{appsec}{appendix}{appendices}

\begin{document}
\section{The first section}\label{sec:1}
\lipsum[2]

\section{The second section}
\Cref{sec:1} tells us something, while \cref{app:1} tells us something else!

\begin{appendices}
  \crefalias{section}{appsec}
  \section{The first appendix}\label{app:1}
  \lipsum[2]
\end{appendices}

\end{document}
|improve this answer|||||
  • 2
    Perhaps it should be obvious, but just to note: if you want a lowercase (or otherwise different) prefix mid-sentence, you need to define \Crefname and \crefname – OJFord Jun 19 '17 at 13:58
  • 1
    It can also be helpful in some circumstances to add additional lines at the beginning of the appendices like \crefalias{subsection}{appsec}, in which case references to subsections in the appendix will have the correct label as well. – Jim Garrison May 30 '18 at 21:35
  • \crefname is for defining the lowercase form of the reference name and \Crefname is for defining the uppercase form. It would be better to use \crefname{appsec}{appendix}{appendices} or \Crefname{appsec}{Appendix}{Appendices} in this example to fit with the intent of the cleveref package. The package provides the option capitalize for users who wish all references to be capitalized. – RobotRaven Mar 18 at 22:15
  • @RobotRaven Many thanks. I turns out only the \Crefname variant respects the class option. – Andrew Swann Mar 19 at 8:11
  • @OJFord Please see the new answer, which addresses this issue too. – Andrew Swann Mar 19 at 8:31
1

I managed it without using \cleverref's more complicated features (crefname, crefalias or appsec) by using \appendix instead. You need to place \cref underneath \appendix for \cref to work out-of-the-box. You have two approaches:

  1. Use \appendix and not \begin{appendices}—the table of contents won't show an "Appendices" header.
\appendix
\chapter{Literacy Methodologies for Non-Dominant Languages}
{\label{a1}}
...
\cref{a1}

evidence of only "A" in the table of contents

  1. Use both \appendix and \begin{appendices}. Both "Appendices" and "A" will appear in the table of contents, albeit at the same visual hierarchy.
\usepackage[toc,page]{appendix}
% [page] gets you a page just to announce the appendices
...
\begin{appendices}
    \appendix
    \chapter{Literacy Methodologies for Non-Dominant Languages}
    {\label{a1}}
\end{appendices}
...
\cref{a1}

evidence of "Appendices" and "A" in the table of contents

  1. Update: Adjust the import parameters of \appendix to get the table of contents just right.
\usepackage[titletoc]{appendix}
...
\begin{appendices}
    \appendix
    \chapter{Literacy Methodologies for Non-Dominant Languages}
    {\label{a1}}
\end{appendices}
...
\cref{a1}

enter image description here

Either way, the text from \cref will say "Appendix A".

evidence that \appendix creates "Appendix A"

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.