將 \ref{} 放入 \aaalphanum 內

將 \ref{} 放入 \aaalphanum 內

我試圖使用 \ref 引用標籤並輸出字母(例如“A”)而不是數字(例如 1)。

我在某處讀過使用 \AAAlphanum{\ref{my_label}} 但此命令失敗

缺失數字,視為零。

任何幫助是極大的讚賞。

答案1

您可以透過多種方式實現這一目標:

在此輸入影像描述

\documentclass{article}
\usepackage{zref,refcount,alphalph,hyperref}

\makeatletter
\zref@newprop{AlphAlphcntr}[??]{\AlphAlph{\value{section}}}
\newcommand{\mylabel}[1]{\zref@labelbyprops{#1}{AlphAlphcntr}}
\newcommand{\myref}[1]{\zref@refused{#1}\zref@extract{#1}{AlphAlphcntr}}
\makeatother

\setlength{\parindent}{0pt}% Just for this example

\begin{document}

\section{A section}\label{sec:mysection}\mylabel{sec:mysection}
Section~\ref{sec:mysection}. \par
Section~\AlphAlph{\getrefnumber{sec:mysection}}. \par
Section~\myref{sec:mysection}.

\end{document}

第一個引用使用\ref,它預設為 所\the<counter>設定的值(在本例中為\arabic{section})。第二個參考使用\getrefnumber由提供的可擴展refcount。最後一個參考使用自訂屬性清單(借助zref) 僅儲存和/或檢索計數器\AlphAlph的版本section

以上都可以擴充使用hyperref, 當然。

相關內容