Text FormattingNo numbers at some sections headings, but interactive

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

No numbers at some sections headings, but interactive

Post by svend_tveskaeg »

Hi all.

First: The Headline is not very good; I apologise for this. I could not come up with anything better. :(

Now, consider the following MWE:

Code: Select all

\documentclass{article}

\usepackage{hyperref}

\begin{document}

\tableofcontents

\vspace{5cm}

\section{Introduction}
\label{IntroOne}

\section{Further Introduction}
\label{IntroTwo}

\part{The First Part}
\label{PartOne}

\section{The First Section in the Actual Text}
\label{SectionOne}

\end{thebibliography}

\end{document}
All the sections are interactive in the ToC as I would like it, but how do I switch off the section numbers in all the sections before the (first) part command, e.i., in the ToC, I would like the entries `1 Introduction', `2 Further Introduction', and `3 The First Section in the Actual Text' to read `Introduction'. `Further Introduction', and `1 The First Section in the Actual Text', respectively, while they are all interactive.

How do I do this?

Thank you in advance!

P.S. If I use the following rather ugly attempt, I get rid of the numbers but the ToC entries before the first part are not interactive.

Code: Select all

\documentclass{article}

\usepackage{hyperref}

\begin{document}

\tableofcontents

\vspace{5cm}

\section*{Introduction}
\label{IntroOne}
\addtocontents{toc}{\protect\section*{Introduction}}

\section*{Further Introduction}
\label{IntroTwo}
\addtocontents{toc}{\protect\section*{Further Introduction}}

\part{The First Part}
\label{PartOne}

\section{The First Section in the Actual Text}
\label{SectionOne}

\end{document}
Last edited by svend_tveskaeg on Mon Feb 06, 2012 12:55 am, edited 2 times in total.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

No numbers at some sections headings, but interactive

Post by localghost »

That's not the correct way to add unnumbered headings to the ToC.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{hyperref}

\begin{document}
  \tableofcontents

  \bigskip
  \phantomsection
  \section*{Introduction}
  \addcontentsline{toc}{section}{Introduction}

  \phantomsection
  \section*{Further Introduction}
  \addcontentsline{toc}{section}{Further Introduction}

  \part{The First Part}\label{prt:one}
    \section{The First Section in the Actual Text}\label{sec:one}
\end{document}
With the equivalent class from the KOMA Script bundle it would be much easier.

Code: Select all

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{hyperref}

\begin{document}
  \tableofcontents

  \bigskip
  \addsec{Introduction}

  \addsec{Further Introduction}

  \part{The First Part}\label{prt:one}
    \section{The First Section in the Actual Text}\label{sec:one}
\end{document}
For details about those classes refer to the KOMA Script user guide.


Thorsten
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

No numbers at some sections headings, but interactive

Post by cgnieder »

I would use \addcontentsline for adding the entry to the ToC. For hyperref you need to use \phantomsection:

Code: Select all

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\section*{Test}\addcontentsline{toc}{section}{Test}\phantomsection

\section{Second Test}

\end{document}
Regards
site moderator & package author
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: No numbers at some sections headings, but interactive

Post by svend_tveskaeg »

Thank you, both!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply