我正在尝试交叉引用书中未编号的章节和部分。但我发现由于软件包和,\nameref
对未编号的部分不起作用。这是 MWE:latexbangla
\titlesec
\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}
并且出现了一个错误:
Package hyperref Warning: Suppressing empty link on input line 28.
我该如何解决这个问题?
答案1
titlesec
不支持nameref
(或nameref
不支持titlesec
)。您必须手动设置标签名称:
\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}