更改文件中附錄的 \crefname

更改文件中附錄的 \crefname

我想更改文件中附錄部分的引用方式:我希望正文中包含“附錄 A.1”,附錄中包含“A.1 節”。

我嘗試了以下方法:

\documentclass{scrartcl}
\usepackage{cleveref}
\begin{document}
    \cref{foo} and \cref{bar}

    \appendix
    \crefname{subappendix}{section}{sections}

    \section{Foo}\label{foo}
    \cref{foo} and \cref{bar}

    \subsection{Bar}\label{bar}
\end{document}

我期望的輸出如下:

附錄 A 及附錄 A.1

阿福

附錄 A 和A.1 節

A.1 酒吧

但我還在附錄中得到了「附錄A.1」。

看來我只能\crefname在序言中使用並影響整個文件。有沒有辦法只更改附錄的參考名稱?

答案1

apptools包引入了相關條件\IfAppendix\ifappendix

\documentclass{scrartcl}
\usepackage{cleveref}
\usepackage{apptools}
\crefname{subappendix}{\IfAppendix{section}{appendix}}{\IfAppendix{sections}{appendices}s}

\begin{document}
    \cref{foo} and \cref{bar}

    \appendix

    \section{Foo}\label{foo}
    \cref{foo} and \cref{bar}

    \subsection{Bar}\label{bar}
\end{document} 

在此輸入影像描述

相關內容