问题:如何制作cleveref
并nameref
使用\documentclass{wlscirep}
和\section*
?
注意\documentclass{wlscirep}
来自“科学报告投稿模板“。下面我展示了我用cleveref
和测试的案例nameref
:
(1)cleveref
与\documentclass{article}
和\section
\documentclass{article}
\usepackage{cleveref}
\begin{document}
\section{Methods}\label{test}
We see in \cref{test} that ...
\end{document}
(2)cleveref
不适\documentclass{article}
用于\section*
\documentclass{article}
\usepackage{cleveref}
\begin{document}
\section*{Methods}\label{test}
We see in \cref{test} that ...
\end{document}
(3)cleveref
与\documentclass[fleqn,10pt]{wlscirep}
和\section
\documentclass[fleqn,10pt]{wlscirep}
\usepackage{cleveref}
\begin{document}
\section{Methods}\label{test}
We see in \cref{test} that ...
\end{document}
(4)cleveref
不适\documentclass[fleqn,10pt]{wlscirep}
用于\section*
\documentclass[fleqn,10pt]{wlscirep}
\usepackage{cleveref}
\begin{document}
\section*{Methods}\label{test}
We see in \cref{test} that ...
\end{document}
(5)nameref
与\documentclass[fleqn,10pt]{wlscirep}
和\section
\documentclass[fleqn,10pt]{wlscirep}
\usepackage{nameref}
\begin{document}
\section{Methods}\label{test}
We see in \nameref{test} that ...
\end{document}
(6)nameref
不适\documentclass[fleqn,10pt]{wlscirep}
用于\section*
\documentclass[fleqn,10pt]{wlscirep}
\usepackage{nameref}
\begin{document}
\section*{Methods}\label{test}
We see in \nameref{test} that ...
\end{document}
答案1
您的课程使用了 titlesec,而 titlesec 无法正确支持 hyperref 和 nameref。您可以尝试以下方法:
\documentclass[fleqn,10pt]{article}
% loaded by the class
\RequirePackage[explicit]{titlesec}
\usepackage{hyperref}
% new code
\titleformat{name=\section,numberless}
{\large\sffamily\bfseries}
{}
{0em}
{\leavevmode\MakeLinkTarget[section]{}\ignorespaces#1}
[]
\ExplSyntaxOn\makeatletter
\def\ttl@straight@i#1[#2]#3{%
\tl_if_empty:nTF {#2}
{\NR@gettitle{#3}}
{\NR@gettitle{#2}}
\gdef\ttl@savemark{\csname#1mark\endcsname{#3}}%
\let\ttl@savewrite\@empty
\def\ttl@savetitle{#3}%
\gdef\thetitle{\csname the#1\endcsname}%
\if@noskipsec \leavevmode \fi
\par
\ttl@labelling{#1}{#2}%
\ttl@startargs\ttl@straight@ii{#1}{#3}}
\ExplSyntaxOff\makeatother
\begin{document}
\section*{Methods}\label{test}
We see in \nameref{test} that ...
\section{Normal}\label{test2}
\nameref{test2}
\section[short]{Long}\label{test3}
\nameref{test3}
\end{document}