3

I am trying to cross-reference the unnumbered chapters and sections in a book. But I found out \nameref is not working for unnumbered sections due to the packages latexbangla and \titlesec. Here is the MWE:

\documentclass[12pt, oneside]{book}

% Kalpurush font: https://www.omicronlab.com/bangla-fonts.html

\usepackage[banglamainfont=Kalpurush, banglattfont=Kalpurush]{latexbangla}
\setdefaultlanguage[numerals=Bengali, changecounternumbering=true]{bengali} \setcounter{secnumdepth}{5} \setotherlanguage{english}

\usepackage{titling} \setlength{\droptitle}{-5em}

\usepackage{titlesec} \titleformat{\chapter}[display] {\raggedright\normalfont\Huge\bfseries}{{\uccoff\fontfamily{lmr}\selectfont\Huge§,\uccon}\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}{0pt}{0pt}{40pt}

\begin{document}

\chapter{Unnumbered Chapter} \label{chap:1} \section{Unnumbered Section} \label{sec:1} Check \nameref{sec:2} in \nameref{chap:2}.

\chapter{Numbered Chapter} \label{chap:2} \section{Numbered Section} \label{sec:2} Check \nameref{sec:1} in \nameref{chap:1}. % Here, \nameref{sec:1} isn't appearing

\end{document}

And an error is showing up:

Package hyperref Warning: Suppressing empty link on input line 28.

How can I fix this problem?

raf
  • 633

1 Answers1

8

titlesec doesn't support nameref (or nameref doesn't support titlesec). You will have to set the name for the label manually:

\documentclass[12pt, oneside]{book}

\usepackage{titlesec} \usepackage{hyperref} \makeatletter \newcommand\setcurrentname[1]{\def@currentlabelname{#1}} \makeatother \begin{document}

\chapter{Unnumbered Chapter}\setcurrentname{Unnumbered Chapter}\label{chap:1} \section{Unnumbered Section}\setcurrentname{Unnumbered Section}\label{sec:1} Check \nameref{sec:2} in \nameref{chap:2}.

\chapter{Numbered Chapter} \label{chap:2} \section{Numbered Section} \label{sec:2} Check \nameref{sec:1} in \nameref{chap:1}. % Here, \nameref{sec:1} isn't appearing

\end{document}

Ulrike Fischer
  • 327,261
  • Thank you so much. But it's not taking me to the exact place of the referenced section. In that case, should I use \phantomsection command? – raf Jul 01 '21 at 17:19