smartef:自訂 \cref 輸出

smartef:自訂 \cref 輸出

我正在使用該cleveref包。我的文檔看起來像這樣:

\documentclass{article}
\usepackage{cleveref}

\begin{document}
\tableofcontents

\section{Section A}
    Refer to \cref{append} for more details.

\appendix
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\Roman{subsubsection}}

\section{Appendix}
    \subsection{Appendix A}
        \subsubsection{Detailed Explanation} \label{append}
            blah
    \subsection{Appendix B}
\end{document}

我必須以這種方式使用小節和小小節,因為附錄本身需要在ToC.

現在我希望我的輸出是這樣的

A部分

有關更多詳細信息,請參閱附錄 A 第 I 部分。

我已經嘗試使用\crefname自訂輸出:

\crefname{secapp}{Anhang \Alph{subsection}, Section}{Appendix \Alph{subsection}, Section}

%Stuff here
\subsubsection{Detailed Explanation} \label[secapp]{append}

secapp但是像這樣定義會導致cleveref列印被呼叫的小節的編號\cref

有沒有辦法像上面描述的那樣使用 來格式化輸出cleveref

謝謝!

答案1

在我看來,命名/編號方案很混亂,但是 usingxassoccnt及其\RegisterPostLabelHook{\zlabel}巨集會自動定義額外的標籤,儲存\thesubsection相關附錄「部分」的 ,\parentCref稍後會提取該標籤。

\documentclass{article}
\usepackage{lipsum}
\usepackage{xassoccnt}
\usepackage{xpatch}
\usepackage{hyperref}
\usepackage[user,counter,hyperref]{zref}
\usepackage{cleveref}

\makeatletter
\AtEndPreamble{
  \newif\if@hyperrefloaded
  \@ifpackageloaded{hyperref}{
    \@hyperrefloadedtrue
  }{
    \@hyperrefloadedfalse
  }
}
\makeatother


\usepackage{xparse}

% Define a new property named 'appendix'

\makeatletter
\zref@newprop{appendix}{\thesubsection}

% Add the new property to the main property list stored with \zlabel, but for \appendix only
\g@addto@macro{\appendix}{%
  \zref@addprops{main}{appendix}%
}

% Command for uppercase output
\NewDocumentCommand{\parentCref}{m}{%
  \zref@ifrefundefined{#1}{%
    \Cref{#1}%
  }{%
    \if@hyperrefloaded
    \hyperlink{\zref@extract{#1}{anchor}}{\appendixname\ \zref@extract{#1}{appendix}, Section \zref@extract{#1}{default}}%
    \else
    \appendixname\ \zref@extract{#1}{appendix}, Section \zref@extract{#1}{default}%
    \fi
  }%
}
\makeatother


\AtBeginDocument{%
 \RegisterPostLabelHook{\zlabel}
}

\begin{document}


\section{Normal section} \label{firstsection}
Refer to \parentCref{append} for more details, but don't forget \parentCref{append:b}.

\appendix
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\Roman{subsubsection}}


\clearpage

\section{Appendix}
\subsection{Appendix A}
\subsubsection{Detailed Explanation} \label{append}
blah
\subsection{Appendix B} \label{appendix:B}
\subsubsection{Even more detailed explanations} \label{append:b}


\end{document}




%\crefname{subsubappendix}{\appendixname \Alph{subsection}, Section}{\appendixname \Alph{subsection}, Section}

\crefformat{subsubappendix}{#2\appendixname\ thesubappendix, Section  #1#3}
\Crefformat{subsubappendix}{#2\appendixname\ thesubappendix, Section  #1#3}

\begin{document}
\tableofcontents

\section{Section A} \label{firstsection}
Refer to \cref{append} for more details, but don't forget \Cref{append:b}.

\appendix
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\Roman{subsubsection}}



\section{Appendix}
\subsection{Appendix A}
\subsubsection{Detailed Explanation} \label{append}
blah
\subsection{Appendix B} \label{appendix:B}
\subsubsection{Even more detailed explanations} \label{append:b}

\end{document}

在此輸入影像描述

相關內容