
Considere o seguinte MWE:
\documentclass{scrbook}
\usepackage{appendix}
\usepackage{cleveref}
\usepackage{etoolbox}
\BeforeBeginEnvironment{appendices}{%
\crefname{chapter}{appendix}{appendices}%
%\Crefname{chapter}{Appendix}{Appendices}%
}
\AfterEndEnvironment{appendices}{%
\crefname{chapter}{chapter}{chapters}%
%\Crefname{chapter}{Chapters}{Chapters}%
}
\begin{document}
\noindent Reference to~regular chapter: \cref{chp:regular_chapter}.
\noindent Reference to~appendix chapter: \cref{chp:appendix_chapter}.
\chapter{Regular chapter} \label{chp:regular_chapter}
Regular chapter text.
\begin{appendices}
\chapter{Appendix chapter} \label{chp:appendix_chapter}
Appendix chapter text.
\end{appendices}
\end{document}
Isso resulta na seguinte saída:
Embora o resultado seja desejado como abaixo:
Eu me pergunto como a tentativa acima de redefinir localmente cleveref
o nome para referências de capítulos pode ser corrigida para funcionar conforme planejado.
Em geral, preciso de uma solução para usar \crefname
macro em escopo local.
Adicionar \begingroup
/ \endgroup
não ajudou.
Como uma melhoria adicional, o nome de referência original dos capítulos pode ser armazenado inicialmente e restaurado após o final do appendices
ambiente (em vez do par chapter
/ chapters
strings codificado no MWE).
Responder1
O pacote cleveref
redefine a opção \appendix
. Se você adicionar este comando (com ou sem appendices
ambiente) você obterá as referências desejadas em seu MWE. Mas não há comando para voltar às referências regulares dos capítulos.
Uma solução é usar o argumento opcional de label
. Este argumento opcional adicional cleveref
também é fornecido por:
\documentclass{scrbook}
\usepackage{appendix}
\usepackage{cleveref}
\begin{document}
\noindent Reference to regular chapter: \cref{chp:regular_chapter}.
\noindent Reference to appendix chapter: \cref{chp:appendix_chapter}.
\noindent Referece to another regular chapter: \cref{chp:another}.
\chapter{Regular chapter} \label{chp:regular_chapter}
Regular chapter text.
\begin{appendices}
\chapter{Appendix chapter}
\label[appendix]{chp:appendix_chapter}% <- changed (optional argument added)
Appendix chapter text.
\end{appendices}
\chapter{Another regular chapter}\label{chp:another}
\end{document}
Responder2
Depoisesdd responderConsegui fazer isso de uma forma um pouco mais automatizada:
\documentclass{scrbook}
\usepackage{appendix}
\usepackage{cleveref}
\begin{document}
\noindent Reference to~regular chapter: \cref{chp:regular_chapter}.
\noindent Reference to~appendix chapter: \cref{chp:appendix_chapter}.
\noindent Reference to~another regular chapter: \cref{chp:another_regular_chapter}.
\chapter{Regular chapter} \label{chp:regular_chapter}
Regular chapter text.
\begin{appendices}
\appendix
\chapter{Appendix chapter} \label{chp:appendix_chapter}
Appendix chapter text.
\end{appendices}
\renewcommand{\thechapter}{\arabic{chapter}}
\chapter{Another regular chapter} \label{chp:another_regular_chapter}
Another regular chapter text.
\end{document}