
次の 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}
出力は次のようになります。
結果は以下のようになることが望まれます。
上記のように地域的に再定義する試みは、cleveref
意図したとおりに動作するように修正できるかどうか疑問に思います。
\crefname
一般的に、ローカルスコープ内でマクロ を使用
するためのソリューションが必要です。/\begingroup
\endgroup
も役に立ちませんでした。
追加の改善として、章の元の参照名が最初に保存され、環境の終了後に復元される可能性があります( MWE にハードコードされた/文字列のペアappendices
の代わりに)。chapter
chapters
答え1
パッケージはcleveref
スイッチを再定義します\appendix
。このコマンドを追加すると(appendices
)、MWE で必要な参照が取得されます。ただし、通常の章の参照に戻すコマンドはありません。
解決策としては、 のオプション引数を使用することですlabel
。この追加のオプション引数は によっても提供されますcleveref
。
\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}
答え2
後esddの 答え私はそれをもう少し自動化された方法で実行することができました:
\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}