0

My document numbers chapters and sections like this:

1. Chapter
  1.1 Section
    1.1.1 Subsection
      Subsubsection

For the first subsection \subsection{First}\label{subsec:first}, for example, cleveref would correctly reference:

As described in \cref{subsec:first}` lorem ipsum...

as

As described in Section 1.1.1 lorem ipsum...

However, since subsubsections do not have numbering, any

\cref{subsubsec:first-subsubsec}

just results in the same

Section 1.1.1

reference.

I would like to have the subsubsection named, so for

\subsubsection{Apples}\label{subsubsec:apples}
...
\subsubref{subsubsec:apples}

It would produce 1.1.1 Apples instead of just 1.1.1 where the reference to the actual subsubsection would get lost.

So far, I implemented this via:

\newcommandx{\subsubref}[1]{\cref{#1} \nameref{#1}}

Is there any way to dynamically decide what is being referenced and treat subsubsections differently?

In simple pseudo-code:

if type of ref == subsubsection:
    \cref{#1} \nameref{#1}
else:
    \cref{#1}
daniel451
  • 183
  • 2
    Note that you are much more likely to get any help if you provide a full but minimal example that others can copy and work with as is – daleif Jan 11 '24 at 08:32
  • 1
    From the duplicate: if you copy all the code and change the \creflabelformat line to \creflabelformat{subsubsection}{#2#1 \nameref*{\@lastusedlabel}#3} it gives the desired output. – Marijn Jan 11 '24 at 10:26

0 Answers0