2

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}
5
  • Interestingly, your example works just fine if titlesec and the \sectionbreak is removed
    – daleif
    Commented Nov 4, 2020 at 14:07
  • nameref does work with starred section, titlesec is the problem. Commented Nov 4, 2020 at 14:08
  • I need titlesec to adjust my heading styles. Is there any way how I can do that and still use \nameref in the way I want?
    – s6hebern
    Commented Nov 4, 2020 at 14:55
  • What do you want your heading styles to look like? Commented Nov 4, 2020 at 17:31
  • {\normalfont\LARGE\bfseries}{\thesection}{1em}{} with Calibri as the default bold font.
    – s6hebern
    Commented Nov 5, 2020 at 8:54

1 Answer 1

2

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 .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .