
我的文件中有一個附錄,我想透過其在文本中的名稱來引用。我\section*
在這裡使用帶有星號的命令,因為我不希望附錄出現在目錄中。但是,\nameref
只需在「附錄」一詞所在的位置留一個空格即可。
感謝評論,我現在可以看到問題實際上是titlesec
包。我希望我的部分Appendix
在目錄中顯示為非編號項目,但同時,我想按照\nameref
上面的說明進行引用。所以我編輯了我的範例,現在看起來像這樣:
\documentclass[11pt, oneside, a4paper]{article}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\LARGE\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\normalfont\Large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}{\normalfont\large\bfseries}{\thesubsubsection}{1em}{}
\titleformat{\paragraph}[runin]{\normalfont\large\bfseries}{\theparagraph}{1em}{}
\usepackage[hidelinks]{hyperref}
\usepackage{nameref}
\newcommand{\sectionbreak}{\clearpage}
\begin{document}
\tableofcontents % added this line
\section{Section 1}
\label{sec:section_1}
All that can be seen in the \nameref{sec:appendix}.
\section*{Appendix}
\label{sec:appendix}
\addcontentsline{toc}{section}{Appendix} % added this line
Here comes the appendix.
\end{document}
答案1
由於這個問題是在我使用 尋找相同衝突的答案時出現的titlesec
,hyperref
並且\section*{}
需要標記,所以我想分享幾年後 Ulrike Fisher 在論壇上發布的解決方法。因此,這個問題將與該答案交叉鏈接,從而使所有人受益。
Ulrike 定義了一個新指令,可用於擴充需要標籤的加星號部分(和其他部分)。你可以在這裡找到她的答案:由於 titilesec 和 Latexbangla,nameref 不適用於未編號的部分。
'titlesec
Heiko Oberdiek 在這個問題中解釋了與hyperref
/ 的組合nameref
不起作用的原因:與 hyperref 和 titlesec 衝突。