# Having both [alternative heading] and no section* numbering

I can remove section numbering by using \section*{My Title for the Section}.

I can provide an optional heading for \nameref by using \section[Section Title]{My Title for the Section}.

But I can't seem to combine them:

\section*[Section Title]{My Title for the Section}
\section[Section Title]*{My Title for the Section}


Both break stuff:

How can I give a section an alternative heading and prohibit numbering?

A minimal working example of what I want would be:

\section*[Section Title]{My Title for the Section}
\label{sec:title}

Referring to the \nameref{sec:title} section.


producing

Referring to the Section Title section.

You could use \addcontentsline to add the short title to ToC.

I think you could modify \@currentlabelname to set the short title instead of the long one.

I have also created a macro with the help of this Werner's post.

\documentclass{book}
\usepackage{hyperref}
\makeatletter
\newcommand{\mysection}[2][\@empty]{%
\section*{#2}
\def\@currentlabelname{\ifx\@empty#1\relax#2\else#1\fi}}
\makeatother

\begin{document}
\tableofcontents
\mysection[Short title]{Long title}\label{sec:title}
A section without number with a long title and a short one.
\mysection{No need short title}\label{sec:anothertitle}
A section without number with one title only.
\section{Normal section}
Name reference to the short title of the first section: \nameref{sec:title}.

Name reference
to the title of the second section: \nameref{sec:anothertitle}.
\end{document}


• While I did mention table of contents in my post (will edit that out now for clarity), my main purpose is to get \nameref{sec:title} to work properly. So good try, but no. Sorry for not being clear. – lindhe Sep 21 '17 at 7:23
• No. In your example, I want \nameref{sec:title} to produce "Short title". – lindhe Sep 21 '17 at 8:13
• I think this is about as good as we'll get. I'm a bit disappointed that there seems to be no easy way around this, but after looking around some I think this is one of the better ways to go at it. Thanks. – lindhe Sep 21 '17 at 17:46
• @lindhe Maybe with KOMA is easier... thank you for accepting my answer! – CarLaTeX Sep 21 '17 at 18:00