4

I need sections included in the TOC, but not in the body text for a PDF output; so when I click the section at TOC, it will jump to the related page [where section header/title is not displayed]. How do I do this?

5

It's an unusual request, but the titlesec package can help you here: use the explicit package option and do not use #1 in \titleformat; \titlespacing can be used to suppress the spacing associated to the sectional unit:

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{hyperref}
\usepackage{lipsum}

\titleformat{\section}{}{}{0em}{}
\titlespacing*{\section}{0pt}{-12pt}{0pt}

\begin{document}

\tableofcontents

\section{Test Section One}
\lipsum[1-10]
\section{Test Section Two}
\lipsum[1-10]

\end{document}

With this approach, all you have to do to recover the section titles in your document is to comment out (or delete) the \titleformat, \titlespacing lines.

2
  • Will this ensure vertical spacing of section suppressed?
    – Firdews
    May 6 '12 at 19:49
  • @Firdews: it does now in my updated answer. May 6 '12 at 19:58
4

Here is a solution using \phantomsection. In the example, the words "Hidden Section" would be replace with whatever the name of your section is.

Code/Example:

\documentclass[]{article}

\usepackage[english]{babel}
\usepackage[]{lipsum}

\usepackage{hyperref} % needed for \phantomsection

\begin{document}
\setcounter{tocdepth}{5}
\tableofcontents
\clearpage

\lipsum[1-7]

\phantomsection
\addcontentsline{toc}{section}{Hidden section}% <-- replace "Hidden section" with your section name
\lipsum[1-7]

\end{document}
-1

Instead of \section{I do not want you} use \addcontentsline{toc}{section}{I do not want you} like in the following MWE.

\documentclass{article}
\begin{document}
\tableofcontents
\addcontentsline{toc}{section}{I do not want you}
\end{document}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.