0

As per the answer to this question, I have customised my subsubsection labels as follows to automatically include the part and chapter numbers:

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

which gives labels of the form:

Pt 1, Ch 2, 3.4.5

Is it possible to insert the title of a subsection as part of this formatting? I'm imagining something like:

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

hopefully giving:

Pt 1, Ch 2, [subsection title] 3.4.5

Thank you.

Bells12
  • 37
  • 5

1 Answers1

2

Well you can, see below. But I don't think that it is a good idea. You are storing all the various data together inside the label, and that means that you no longer have the option to reference simply the number 1.1, e.g. if you want to reference simply the previous section. Imho it is much better to use either zref or the new LaTeX properties to store the data individually and to build a complex reference when you reference the label. See e.g. 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}

enter image description here

Ulrike Fischer
  • 327,261
  • Thank you. I agree, this isn't an ideal format - I'm trying to replicate a Word template used in my workplace, to a) convince them to use LaTeX for complex documents in the first place, and b) argue to simplify this kind of formatting where its currently used.

    Also, by adapting this answer I've been able to insert the labels of higher or lower sectional units where needed.

    – Bells12 Jan 05 '24 at 14:54