titlesec icon indicating copy to clipboard operation
titlesec copied to clipboard

titlesec is incompatible with unnumbered nameref

Open pintergreg opened this issue 2 years ago • 0 comments

I have to use a class with titlesec and unnumbered sections, but I want to (name)reference a section, which does not work. After some debugging I found out that the issue originates from titlesec.

I don't really understand what it does, but at the titleformat directive, the documentation says "Both 〈label 〉 and 〈sep〉 are ignored in starred versions of sectioning commands".

Is it possible to use unnumbered namerefs ant titlesec at the same time?

Thanks,

MWE:

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{titlesec}

\titleformat{\section}[hang]
  {\usefont{T1}{qhv}{b}{n}}
  {}
  {0em}
  {\hspace{-0.4pt}\Large \thesection\hspace{0.6em}}

\titleformat{name=\section,numberless}[hang]
  {\usefont{T1}{qhv}{b}{n}}
  {}
  {0em}
  {\hspace{-0.4pt}\Large}

\begin{document}

\section*{Unnumbered section}
\label{sec:un}

Some text

\section{Numbered section}
\label{sec:n}

Some text, ref unnumbered (\nameref{sec:un}) and numbered (\ref{sec:n}, \nameref{sec:n})

\end{document}

N.B.: hyperref implicitly includes nameref package, that provides \nameref.

pintergreg avatar Jul 27 '23 17:07 pintergreg