Thanks to visit codestin.com
Credit goes to github.com

Skip to content

titlesec is incompatible with unnumbered nameref #63

@pintergreg

Description

@pintergreg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions