1

I have an appendix in my document which I want to reference by its name in the text. I use the starred \section* command here, because I do not want the appendix to appear in the TOC. However, \nameref simply puts an empty space where the word "Appendix" should be.


Thanks to the comments, I now can see that the problem is actually the titlesec package. I want my section Appendix to appear as a non-numbered item in the TOC, but at the same time, I want to do there referencing with \nameref as explained above. So I edited my example to now look like this:

\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}

s6hebern
  • 297

1 Answers1

1

Since this question popped up as I was searching for answers to the same conflict using titlesec, hyperref and \section*{} that needed labelling, I like to share the workaround that Ulrike Fisher published on the forum a few years later. So this question will be crosslinked to that answer and hence be of benefit of all.

Ulrike defined a new command, that can be used to augment the starred section (and others) requiring a label. You can find her answer here: nameref is not working for unnumbered sections due to titilesec and latexbangla .

The reason why the combination 'titlesec with hyperref / nameref doesn't work is explained by Heiko Oberdiek in this question: Conflict with hyperref and titlesec .

alchemist
  • 1,761