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.

lindhe
  • 264
  • 1
    Slightly related: https://tex.stackexchange.com/questions/33696/no-section-numbers-but-still-have-pdf-bookmarks-with-hyperref/33702#33702 and https://tex.stackexchange.com/questions/17048/make-chapter-same-as-unnumbered-chapter-using-memoir – lindhe Sep 21 '17 at 07:03
  • https://github.com/johannesbottcher/unnumberedtotoc/ might help – Johannes_B Sep 21 '17 at 07:10
  • 1
    If you use a KOMA class you should look at its extra sectioning macros. – TeXnician Sep 21 '17 at 07:13
  • Will anything from the regular classes break if I use the KOMA class instead? – lindhe Sep 21 '17 at 07:25
  • By the way, if you want all sections to be unnumbered, there is a different way. – Johannes_B Sep 21 '17 at 08:17
  • KOMA classes are extended and feature rich alternatives to the stanard classes. There shouldn't be any problems. Some packages specially made for the standard classes are incompatible eith KOMA classes – Johannes_B Sep 21 '17 at 08:19
  • @Johannes_B Thanks, but I only want it for this particular section. – lindhe Sep 21 '17 at 08:21

1 Answers1

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

CarLaTeX
  • 62,716
  • 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 07:23
  • No. In your example, I want \nameref{sec:title} to produce "Short title". – lindhe Sep 21 '17 at 08: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