1

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:

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

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.

7

1 Answer 1

3

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}
    \addcontentsline{toc}{section}{\ifx\@empty#1\relax#2\else#1\fi}
    \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}

enter image description here

4
  • 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, 2017 at 7:23
  • No. In your example, I want \nameref{sec:title} to produce "Short title".
    – lindhe
    Sep 21, 2017 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, 2017 at 17:46
  • @lindhe Maybe with KOMA is easier... thank you for accepting my answer!
    – CarLaTeX
    Sep 21, 2017 at 18:00

You must log in to answer this question.

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