使用 \labelformat 在標籤中包含小節標題

使用 \labelformat 在標籤中包含小節標題

根據答案這個問題,我已經自訂了我的小節標籤,如下所示,以自動包含零件號碼和章節號碼:

\labelformat{subsubsection}{Pt~\arabic{part}, Ch~\thechapter, \thesubsubsection}

它給出了以下形式的標籤:

第 1 部分,第 2 章,3.4.5

是否可以插入小節的標題作為此格式的一部分?我正在想像這樣的事情:

\labelformat{subsubsection}{Pt~\arabic{part}, Ch~\thechapter, [code for subsection title] \thesubsubsection}

希望給予:

第 1 部分,第 2 章,[小節標題] 3.4.5

謝謝。

答案1

好吧,你可以,請參閱下文。但我認為這不是一個好主意。您將所有各種資料一起儲存在標籤內,這意味著您不再可以選擇僅引用數字1.1,例如,如果您想只引用上一節。恕我直言,最好使用 zref 或新的 LaTeX 屬性來單獨儲存資料並在引用標籤時建立複雜的引用。參見例如https://tex.stackexchange.com/a/325319/2388

\documentclass{book}
\usepackage{xr-hyper}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\makeatletter
\labelformat{section}{Pt~\arabic{part}, Ch~\thechapter, \thesection~\@currentlabelname}
\labelformat{subsection}{Pt~\arabic{part}, Ch~\thechapter, \thesubsection~\@currentlabelname}
\makeatother
\begin{document}
\part{}
\label{part: 1}

\chapter{Chapter}
\section{My Section}\label{sec}
\subsection{My Subsection}\label{subsec}

\ref{sec}, \ref{subsec}
\end{document}

在此輸入影像描述

相關內容