Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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.

share|improve this answer
    
Will this ensure vertical spacing of section suppressed? –  Firdews May 6 '12 at 19:49
    
@Firdews: it does now in my updated answer. –  Gonzalo Medina May 6 '12 at 19:58

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}
share|improve this answer

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}
share|improve this answer
    
Welcome to TeX.SX! Usually we prefer answering in form of minimal working examples so that others may easily test the proposed solution. –  Claudio Fiandrino May 12 at 13:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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